An asterisk *means combining all other arguments into one list, called an argument. Ampersand &means that if the block is passed to the method call (i.e. it block_given?will be true), then save it in a new Proc called an argument (or, as it seems to me, a pseudo-argument).
def foo(*a)
puts a.inspect
end
foo(:ok)
foo(1, 2, 3)
def bar(&b)
puts b.inspect
end
bar()
bar() {|x| x+1}
Note that it &should be displayed last if used, and *may be the last before it, or it should be the last.
* "" ( "" ), :
def gah(a, b, c)
puts "OK: a=#{a}, b=#{b}, c=#{c}"
end
gah(*[1, 2, 3])
gah(1, *[2, 3])
, & "" Proc :
def zap
yield [1, 2, 3] if block_given?
end
zap()
zap(&Proc.new{|x|puts x.inspect})