A
Adam Block
I'm reading log file settings from a YAML file. Since Logger.new can
take either an IO object or string, the YAML could look like:
logger:
output: STDOUT
or
logger:
output: /foo/bar
The problem is that the YAML structure is loaded as strings, so if I
specify STDOUT I get a log file named "STDOUT". Is there an elegant way
around this problem? I see two less-elegant ways:
if yaml["logger"]["output"] == "STDOUT" then
log = Logger.new(STDOUT)
else
...
end
or
log = eval('Logger.new(' + yaml["logger"]["output"] + ')')
etc.
I know casting is bad. Any suggestions appreciated. Thanks!
take either an IO object or string, the YAML could look like:
logger:
output: STDOUT
or
logger:
output: /foo/bar
The problem is that the YAML structure is loaded as strings, so if I
specify STDOUT I get a log file named "STDOUT". Is there an elegant way
around this problem? I see two less-elegant ways:
if yaml["logger"]["output"] == "STDOUT" then
log = Logger.new(STDOUT)
else
...
end
or
log = eval('Logger.new(' + yaml["logger"]["output"] + ')')
etc.
I know casting is bad. Any suggestions appreciated. Thanks!