Friday, April 5, 2013

Ruby String Interpolation

Use a combination of the eval command and the #{ } idiom to get the values of Logger constants.


>> Logger.constants.each {|i| puts "Logger::#{i} = " + eval("Logger::#{i}").to_s}
Logger::VERSION = 1.2.7
Logger::ProgName = logger.rb/31641
Logger::Error = Logger::Error
Logger::ShiftingError = Logger::ShiftingError
Logger::Severity = Logger::Severity
Logger::SEV_LABEL = ["DEBUG", "INFO", "WARN", "ERROR", "FATAL", "ANY"]
Logger::Formatter = Logger::Formatter
Logger::LogDevice = Logger::LogDevice
Logger::Application = Logger::Application
Logger::SimpleFormatter = Logger::SimpleFormatter
Logger::DEBUG = 0
Logger::INFO = 1
Logger::WARN = 2
Logger::ERROR = 3
Logger::FATAL = 4
Logger::UNKNOWN = 5



References

http://lexsheehan.blogspot.com/2013/04/temporarily-disable-executed-sql.html http://en.wikipedia.org/wiki/String_interpolation



Sponsor Ads(Please visit one if you liked this article. Thanks!)

1 comment: