From: Ray K. on 23 Jul 2010 03:45 Hello from Germany, I'm looking for a brief snippet that I've seen somewhere lately, but can't remember where. It did override Object so one could add code to an existing method - without just overriding it. Anyone have a clou? I'll keep looking, maybe I can provide more details later. Thanks Ray -- Posted via http://www.ruby-forum.com/.
From: Robert Klemme on 23 Jul 2010 05:01 2010/7/23 Ray K. <raineronrails(a)gmail.com>: > Hello from Germany, Hi Timezonefellow, > I'm looking for a brief snippet that I've seen somewhere lately, but > can't remember where. > > It did override Object so one could add code to an existing method - > without just overriding it. > > Anyone have a clou? I'll keep looking, maybe I can provide more details > later. Rainer, vielleicht meinst Du so etwas? irb(main):001:0> class Foo irb(main):002:1> def bar irb(main):003:2> puts "bar" irb(main):004:2> end irb(main):005:1> end => nil irb(main):006:0> f = Foo.new => #<Foo:0x1015ce1c> irb(main):007:0> f.bar bar => nil irb(main):008:0> class Foo irb(main):009:1> alias _bar bar irb(main):010:1> def bar irb(main):011:2> puts "new bar before" irb(main):012:2> _bar irb(main):013:2> puts "new bar after" irb(main):014:2> end irb(main):015:1> end => nil irb(main):016:0> f.bar new bar before bar new bar after => nil irb(main):017:0> Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
|
Pages: 1 Prev: Error on test case Next: Ruby sandbox secure enough for evaluating any code? |