Jesús Gabriel y Galán wrote:
> irb(main):001:0> class A
> irb(main):002:1> end
> => nil
> irb(main):005:0> a = 3
> => 3
> irb(main):006:0> A.class_eval do
> irb(main):007:1* define_method(:go) do
> irb(main):008:2* puts a
> irb(main):009:2> end
> irb(main):010:1> end
> => #<Proc:0xb7dbffd0@(irb):7>
> irb(main):011:0> A.new.go
> 3
> => nil

Just curious... is there any difference between using define_method and 
def in this case?  It seems they achieve the same effect.  Why would one 
be preferred over the other?

>> A = Class.new
=> A
>> A.class_eval do
?>     define_method(:test) do
?>       puts "Testing!"
>>     end
>>   end
=> #<Proc:0xb72bdc40@(irb):3>
>> A.new.test
Testing!
=> nil
>> B = Class.new
=> B
>> B.class_eval do
?>     def test
>>       puts "Testing!!"
>>     end
>>   end
=> nil
>> B.new.test
Testing!!
=> nil

Thanks.

Jeff
-- 
Posted via http://www.ruby-forum.com/.