Re: Create a method with name, containing illegal characters



On 10/31/07, Phrogz <phrogz@xxxxxxx> wrote:
On Oct 31, 7:34 am, kylichuku <Kirill.Isha...@xxxxxxxxx> wrote:
I need to create a method with name, that contains '-' character. Is
it possible, and if the answer is "yes", how can I do it?

lim2:~ phrogz$ irb
irb(main):001:0> class Foo
irb(main):002:1> define_method("a-b") do
irb(main):003:2* puts "What a strange need!"
irb(main):004:2> end
irb(main):005:1> end
=> #<Proc:0x00354328@(irb):2>

irb(main):006:0> f = Foo.new
=> #<Foo:0x34f454>

irb(main):007:0> f.a-b
NoMethodError: undefined method `a' for #<Foo:0x34f454>
from (irb):7
from :0

irb(main):008:0> f.send( "a-b" )
Cool I did not know one could do this
What a strange need!
Not strange at all, how often did I
gsub("-","_") in my DSLs

Cheers
Robert








--
what do I think about Ruby?
http://ruby-smalltalk.blogspot.com/

.



Relevant Pages