[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: passing function into another function

Gavin Kistner

9/11/2006 11:13:00 PM

From: Joe Van Dyk [mailto:joevandyk@gmail.com]
> def do_something_with_a_report report
> # calls Reports::This or Reports::That, dtermined by what report is
> # something like report.call ?
> end

class Reports
def self.this
puts "#{self} is doing 'this'"
end
def self.that
puts "#{self} is doing 'that'"
end
def self.run_report( report_name )
send( report_name )
end
end

def do_something_with_a_report( report_name )
Reports.run_report( report_name )
end

do_something_with_a_report( :this )
#=> Reports is doing 'this'

def do_something_with_a_report2( report )
report.call
end

do_something_with_a_report2( Reports.method( :this ) )
#=> Reports is doing 'this'