Forge an Object in the Fires of Mount Ruby why does it do this!


#1



My code works for the lesson to pass but i tried to get smart and display what i had writen which gives me a generator instead of what i expected please help so i can understand fully.


Replace this line with your code. 

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

puts my_message


#2

Not sure if you have touched on this yet, but here goes...

class Message
  attr_reader :from, :to
  @@messages_sent = 0
  def initialize (from,to)
    @from = from
    @to = to
    @@messages_sent += 1
  end
end
my_message = Message.new("Me","You")
puts my_message.from
puts my_message.to
new_message = Message.new(1,2)
puts new_message.from
puts new_message.to

Me
You
1
2
nil

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.