On Thu, Feb 28, 2013 at 4:50 PM, Tukai Patra <[email protected]> wrote: > @Hans - Yes I do understand how `alias` works. Might be you didn't catch > my aim. I have a hope anyone out there might understood my intention.
I hope *you* do. > Let's wait you can see how the same could be done with other way's,if > someone answered it. Meanwhile If I get any solution,I will present here > with explanation. Facts: 1. With alias you copy a method. 2. You can achieve the same with alias_method. 3. You can achieve something similar by doing def new_meth(*a,&b) old_meth(*a,&b) end. 4. When defining a method all previous definitions under that name are gone. 5. Option 2 and 1 actually differ from 3 if you redefine old_meth (exercise for the user). 6. What constitutes dangerous depends on the expectations and the desired behavior. 7. Invoking a method from inside or outside an object (meaning self pointing to the instance to invoke the method on or not) only matters for private methods. irb(main):001:0> class Foo irb(main):002:1> def x; 1; end irb(main):003:1> alias_method :y, :x irb(main):004:1> end => Foo irb(main):005:0> Foo.new.y => 1 irb(main):006:0> class Foo irb(main):007:1> def x; 2; end irb(main):008:1> end => nil irb(main):009:0> Foo.new.y => 1 irb(main):010:0> Foo.new.x => 2 Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- [email protected] | https://groups.google.com/d/forum/ruby-talk-google?hl=en --- You received this message because you are subscribed to the Google Groups "ruby-talk-google" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
