Given a class instance and a string, how do I convert the string to refer to the instance?
class Room
def enter
puts "Welcome!"
end
end
# Rooms are predefined
lounge = Room.new
kitchen = Room.new
study = Room.new
puts "Which room would you like to go to?"
print "> "
room = gets.strip
# User types "lounge"
room.enter # => undefined method `enter' for "lounge":String (NoMethodError)
I understand why I'm getting NoMethodError, but I haven't been able to work out how to convert the room string to refer to the existing instance of Room named lounge.