I have the following Ruby module:
module Test
Constant1 = {
:key1 => :value1,
:key2 => :value2
}
Constant2 = {
:key1 => :value1,
:key2 => :value2
}
end
And I am trying to iterate through the declared Hash constants to print all the keys defined with the following code:
Test.constants.each do |constant|
constant.keys.each do |key|
puts "key: #{key}"
end
end
But I get a NoMethodError: undefined method 'keys' for "Constant2":String and I don’t know how to convert that String into a real costant. Anyone knows how to do it?
This works: