From: Robert Klemme Date: 2010-10-07T21:16:46+09:00 Subject: Re: Can anyone give a an example of this please On Thu, Oct 7, 2010 at 2:01 PM, Kaye Ng wrote: > "code blocks may accept none, one, or more parameters" > > I understand how ONE parameter is passed using the 'each' method. > I also understand how TWO parameters is passed, like in this code > x = { "a" => 100, "b" => 20 } > x.delete_if { |key, value| value < 25 } > p x > > Can anyone give me a very simple and executable code where: > NO parameters is passed, and > THREE parameters is passed 14:14:24 ~$ ruby19 < def none; yield; end > def one; yield 1; end > def three; yield 1,2,3; end > none { puts "called" } > one {|x| puts "Got one: #{x}"} > three {|a,b,c| puts "Got three: #{a}, #{b}, #{c}"} > three {|a| p a} > three {|*a| p a} > CODE called Got one: 1 Got three: 1, 2, 3 1 [1, 2, 3] 14:15:44 ~$ > SIMPLE CODE/SYNTAX ONLY PLEASE, BEGINNER HERE. =D Please do not shout. robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/