Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > passing function into another function

Reply
Thread Tools

passing function into another function

 
 
Joe Van Dyk
Guest
Posts: n/a
 
      09-11-2006
Hi,

I couldn't work out the syntax for the following:

class Reports
def self.This; end
def self.That; end
end

def do_something_with_a_report report
# calls Reports::This or Reports::That, dtermined by what report is
# something like report.call ?
end

I want to do something like:

do_something_with_a_report Reports::This

But that calls Reports::This and sends that value to the
do_something_with_a_report function.

In other words, I want to do something like passing a function pointer
to a function in C.

 
Reply With Quote
 
 
 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      09-11-2006
On Tue, 12 Sep 2006, Joe Van Dyk wrote:

> Hi,
>
> I couldn't work out the syntax for the following:
>
> class Reports
> def self.This; end
> def self.That; end
> end
>
> def do_something_with_a_report report
> # calls Reports::This or Reports::That, dtermined by what report is
> # something like report.call ?
> end
>
> I want to do something like:
>
> do_something_with_a_report Reports::This
>
> But that calls Reports::This and sends that value to the
> do_something_with_a_report function.
>
> In other words, I want to do something like passing a function pointer
> to a function in C.
>


harp:~ > cat a.rb
class Reports
def self.This; p 'This'; end
def self.That; p 'That'; end
This = method 'This'
That = method 'That'
end

def do_something_with_a_report report
report.call
end

do_something_with_a_report Reports::This
do_something_with_a_report Reports::That


harp:~ > ruby a.rb
"This"
"That"

you could also just

do_something_with_a_report Reports::method('This')
do_something_with_a_report Reports::method('That')


-a
--
in order to be effective truth must penetrate like an arrow - and that is
likely to hurt. -- wei wu wei

 
Reply With Quote
 
 
 
 
Joe Van Dyk
Guest
Posts: n/a
 
      09-11-2006
On 9/11/06, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> On Tue, 12 Sep 2006, Joe Van Dyk wrote:
>
> > Hi,
> >
> > I couldn't work out the syntax for the following:
> >
> > class Reports
> > def self.This; end
> > def self.That; end
> > end
> >
> > def do_something_with_a_report report
> > # calls Reports::This or Reports::That, dtermined by what report is
> > # something like report.call ?
> > end
> >
> > I want to do something like:
> >
> > do_something_with_a_report Reports::This
> >
> > But that calls Reports::This and sends that value to the
> > do_something_with_a_report function.
> >
> > In other words, I want to do something like passing a function pointer
> > to a function in C.
> >

>
> harp:~ > cat a.rb
> class Reports
> def self.This; p 'This'; end
> def self.That; p 'That'; end
> This = method 'This'
> That = method 'That'
> end
>
> def do_something_with_a_report report
> report.call
> end
>
> do_something_with_a_report Reports::This
> do_something_with_a_report Reports::That
>
>
> harp:~ > ruby a.rb
> "This"
> "That"
>
> you could also just
>
> do_something_with_a_report Reports::method('This')
> do_something_with_a_report Reports::method('That')


Ah, Object#method. Thank you both!

Joe

 
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
passing array of floats (or vectors) into another function - datascope - hmmm. Very ugly... someone C++ 26 10-24-2011 08:17 PM
Passing arrarys from a function to another function. Foxy Kav C++ 1 04-25-2004 02:58 AM
passing what a function returns to another function Bart Nessux Python 5 02-08-2004 07:55 PM
passing ptr to function to another function Pushkar Pradhan C Programming 4 10-04-2003 09:57 PM
Passing a pointer to member function as a parameter to another member function Newsgroup - Ann C++ 5 07-30-2003 02:54 AM



Advertisments