ruby语法-传值_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > ruby语法-传值

ruby语法-传值

 2011/9/5 8:10:29  foyoto  http://foyoto.iteye.com  我要评论(0)
  • 摘要:=begindeftest1(*a)pa.firstpa.lastpa.lengthendtest1(3,6)#>>#3#6#2<<=end=begindeftest2(a,*b)papbpb.lengthpb.firstendtest2(1)test2(1,:a=>1,:b=>2)#>>#1#[]#0#nil#1#[{:a=>1,:b=>2}]#1#{:a=>1,:b=>2}#<<
  • 标签: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"]












发表评论
用户名: 匿名