Tuesday, 10 September 2013

I want to eval concatenated symbols in ruby

I want to eval concatenated symbols in ruby

I'm trying to find a way to concatenate module and class names to give me
more info. In cases where I can Enumerate things like constants, I want to
tack on to them and eval them somewhat. I've seen something like this
before but just don't remember where.
Errno.constants.sort.each do |name|
string = '#{Errno}::#{name}::#{Errno}'
puts eval("\"" + string + "\"")
end
How might I get something like this to work so that I don't have to
individually list the full name such as
puts Errno::E2BIG::Errno

No comments:

Post a Comment