From: Tammo Freese Date: 2006-08-04T08:20:54+09:00 Subject: Re: define_method vs eval "def ..." Robert Dober wrote: [...] > and it seems to make it into Ruby2 since June > http://pub.cozmixng.org/~the-rwiki/? > cmd=view;name=Ruby2.0BlockParameterAndMultipleValueAssignment > which I consider extremly good news :) I am suprised that the blocks will work in such a way. How do these play together with the new define_method ? Examples from http://pub.cozmixng.org/~the-rwiki/? cmd=view;name=Ruby2.0BlockParameterAndMultipleValueAssignment : - Proc.new{|x| x}.call(0,1) returns 0. - Proc.new{|x,y| [x,y]}.call(0) returns [0,nil]. So missing arguments seem to be set to nil, and additional arguments seem to be ignored. What would happen for this code fragment: proc_one = Proc.new{|x| x} proc_two = Proc.new{|x,y| [x,y]} define_method(:meth_one) &proc_one define_method(:meth_two) &proc_two p proc_one.call(0,1) # returns 0 according to the web page p proc_two.call(1) # returns 1,nil according to the web page p meth_one(0,1) # ??? p meth_two(1) # ??? Would the last two work and return the same result as the direct proc calls? If so, how would we define a method via define_method that takes a fixed number of parameters? If not, where does the magic happen that while the proc accepts the arguments, the method defined by the proc does not? Thanks for your help, Tammo