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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---