# Passing function into another function

**URL:** <https://www.ruby-forum.com/t/passing-function-into-another-function/68357>\
**Category:** Ruby\
**Created:** [September 12, 2006, 1:05am UTC](https://www.ruby-forum.com/t/passing-function-into-another-function/68357 "2006-09-12T01:05:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [September 12, 2006, 1:05am UTC](https://www.ruby-forum.com/t/passing-function-into-another-function/68357/1 "2006-09-12T01:05:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [September 12, 2006, 1:21am UTC](https://www.ruby-forum.com/t/passing-function-into-another-function/68357/2 "2006-09-12T01:21:27Z")

</div>

On 9/11/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > do\_something\_with\_a\_report function.  
> > That = method ‘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

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [September 12, 2006, 1:17am UTC](https://www.ruby-forum.com/t/passing-function-into-another-function/68357/3 "2006-09-12T01:17:27Z")

</div>

On Tue, 12 Sep 2006, Joe Van D. wrote:

> # calls Reports::This or Reports::That, dtermined by what report is
> 
> 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
