Help on Forge an Object in the Fires of Mount Ruby


#1

Hi, this is the code I used for the Forge an Object in the Fires of Mount Ruby:

    class Message
    @@messages_sent = 0
    def initialize(from, to)
        @from = from
        @to = to
        @messages_sent += 1
    end
end

my_message = Message.new("me", "you")

and I was getting an error saying: undefined method `+' for nil:NilClass

Why this is not working and what dose this error mean?


#2

been a while since i done this in ruby, but you define message sent here:

@@messages_sent = 0

but then you call it here:

@messages_sent += 1

and it has only one @ instead of two


#3

Thanks so much! :smile: