Forum: Ruby on Rails SOT: Ruby Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
96146b7a23174e2e024c06a49f845bb8?d=identicon&s=25 Jeffrey L. Taylor (Guest)
on 2008-12-30 10:53
(Received via mailing list)
I have the following code.  It works but it seems to me that there must
be a
clearer, more compact way.  Is there a way in Ruby to pass a method name
to a
method?  Something simpler than a block or lambda?

TIA,
  Jeffrey


module Preload
  def Preload.info_msg(msg)
    Preload.common_msg(msg) {|msg| RAILS_DEFAULT_LOGGER.info msg}
  end


  def Preload.debug_msg(msg)
    Preload.common_msg(msg, lambda{|msg| RAILS_DEFAULT_LOGGER.debug
msg})
  end


  def Preload.common_msg(msg, logger = nil)
    puts msg
    if logger
      logger.call(msg)
    else
      yield msg
    end
    msg
  end
end
This topic is locked and can not be replied to.