I am trying to initialize an object in Ruby, but I get an error: "undefined method `Thing’ for main:Object (NoMethodError)"
However, isn’t that what the initialize method is for?
class Thing
def initialize(id, color)
@id = id
@color = color
end
end
Thing thing = Thing.new(1, "blue")
>Solution :
Local variables are created by simply assigning to them. You don’t have to declare them or specify their type. (in fact, you can’t)
Just write:
thing = Thing.new(1, "blue")