Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Call a method before a method is called?

Thread Tools

Call a method before a method is called?

Ben Johnson
Posts: n/a
Does ruby have "hooks". Where I can define, let's say, a method called
__before that will be called before ANY method call for that class?

Thanks for your help.

Posted via

Reply With Quote
Rodrigo Bermejo
Posts: n/a
You can do it easily this way (depending what you really want):

def lady
puts "ladies go first"

class Myclass
def initialize
def man
puts "you look better from here"

/--> ladies go first
/--> you look better from here

A not OO solution is to use:

(from programming ruby book)

Every Ruby source file can declare blocks of code to be run as the file
is being loaded (the BEGIN blocks) and after the program has finished
executing (the END blocks).

begin code

end code

A program may include multiple BEGIN and END blocks. BEGIN blocks are
executed in the order they are encountered. END blocks are executed in
reverse order.

hope it helps


Posted via

Reply With Quote

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
Is it possible to call button click event before page load on postback GauravGupta ASP .Net 2 07-01-2007 12:16 AM
Function declared before call but defined after - compilation fails C++ 11 05-18-2007 05:13 PM
Function call after switch but before first case - behavior? C++ 9 05-02-2007 10:44 PM
Setting member variables before constructor call C++ 6 01-16-2006 06:07 PM
Before Sunset & Before Sunrise matt r DVD Video 2 11-25-2004 08:37 AM