ruby语法-传值

=begin
def test1(*a)
p a.first
p a.last
p a.length
end
test1(3,6)
#>>
#3
#6
#2
<<
=end

=begin
def test2(a,*b)
p a
p b
p b.length
p b.first
end
test2(1)
test2(1,:a => 1, :b => 2)
#>>
#1
#[]
#0
#nil
#1
#[{:a=>1, :b=>2}]
#1
#{:a=>1, :b=>2}
#<<
=end

=begin
def test3(a,b,*c)
p a
p b
p b.length
p c
p c.length
end
test3(1,:a => 1, :b => 2)
#>>
#1
#{:a=>1, :b=>2}
#2
#[]
#0
#<<
=end

=begin
def test3(a,b,c={})
p a
p b
p b.length
p c
p c.length
end
test3(1,:a => 1, :b => 2)
#>>
#1
#{:a=>1, :b=>2}
#2
#{}
#0
#<<
=end

=begin
def test3(a,b,c)
p a
p b
p b.length
p c
p c.length
end
test3(1,:a => 1, :b => 2)
#>>
#test.rb:81:in `test3': wrong number of arguments (2 for 3) (ArgumentError)
# from test.rb:81
#<<
=end


=begin
def test4(a,b)
p a
p b
end
test4(*[2,3])
#>>
#2
#3
#<<
=end


=begin
def a(a, *b, &block)
p a
p b
block.call
end

a(3,4) {puts "aaa"}
#>>
#3
#4
#aaa
#<<
=end

=begin
def a(a, *b, &block)
p a
p b
block.call
end
a(3) {puts "aaa"}
#>>
#3
#[]
#aaa
#<<
=end


#def link_to(name,options={},html_options=nil)
# p name
# p options
#end

#def link_to_tag(name,options={},html_options=nil,*parameters_for_method_reference)
#link_to(name,options,html_options=nil,*parameters_for_method_reference)
#end
#link_to_tag("submit","http://www.sina.com",{:class=>"button"},["a","b"])


class A
@cached_settings = {}
def self.[](name)
v = @cached_settings[name]
v ? v : (@cached_settings[name] = rand(10))
end
end

p A["a"]
#p A["a"]
#p A["a"]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值