[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [CHALLENGE] better alias_method

Gavin Kistner

9/8/2006 4:30:00 PM

From: ara.t.howard@noaa.gov [mailto:ara.t.howard@noaa.gov]
> i remember that define_method will soon have the ability to
> define methods that take blocks do you know if that's in
> 1.8.5 or the 1.9 branch?

Not in 1.8.5:

p RUBY_VERSION
#=> 1.8.5

class Foo
def self.make_method( name, &block )
define_method( name, &block )
end
end

Foo.make_method( :bar ){ |a|
p a, block_given?
yield a if block_given?
}

f = Foo.new
f.bar( 3 ){ |x| p x*x }
#=> 3
#=> false