Passing function into another function

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'

···

From: Joe Van Dyk [mailto:joevandyk@gmail.com]