From: "James M. Lawrence" Date: 2008-09-17T10:58:07+09:00 Subject: Re: define anonymous module with closure Ara Howard wrote: > cfp:~ > ruby a.rb > "x" > you need to do it this way if you want your method to take a block ...if you are constrained to 1.8.6. % ruby --version ruby 1.8.7 (2008-08-11 patchlevel 72) class A define_method(:f) { |x, &block| puts "A#f argument: #{x}" block.call(88) } end A.new.f(99) { |t| puts "block called with: #{t}" } # => A#f argument: 99 # block called with: 88 Now if you want default parameters, you'll need Ara's example again. Unless you use 1.9... % ruby --version ruby 1.9.0 (2008-09-15 revision 19346) class A t = ->(a = 11, b = 22) { a + b } define_method(:g, &t) end a = A.new p a.g # => 33 p a.g(33) # => 55 p a.g(33, 44) # => 77 From what I gathered, -> was introduced because lambda { |a = 11, b = 22| a + b } was too difficult or ambiguous to parse. My feeling is that -> should be avoided if at all possible, no matter how difficult. To me, -> is a step toward ruby jumping the shark. I want to yell, "Fonzie, don't do it!" (Excuse the Americanisms.) -- Posted via http://www.ruby-forum.com/.