Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Snippet to append code to method

Reply
Thread Tools

Snippet to append code to method

 
 
Ray K.
Guest
Posts: n/a
 
      07-23-2010
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/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      07-23-2010
2010/7/23 Ray K. <(E-Mail Removed)>:
> 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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
the address of list.append and list.append.__doc__ HYRY Python 10 09-26-2007 09:41 AM
Code snippets, tool to convert basic to .snippet xml? Edwin Knoppert ASP .Net 0 11-30-2005 03:45 PM
Is there a code snippet showing how to do a Redirect on a TreeView event Tom ASP .Net 3 12-01-2004 03:04 AM
Request Handler code snippet wanted plz Gil Blais Java 0 04-15-2004 08:23 AM
How can I save my code snippet on toolbox in vs.net? Clare Hsiao ASP .Net 0 02-12-2004 02:01 AM



Advertisments