18/20 Why @from, @to working?


#1

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

Why in the last part is (@from, @to) work? But it doesn't work with from or to by itself? Can someone clarify this?

I thought the arguments (from, to) in initialize would be the correct way to write out the last part, but it says I am wrong when I do this?


#2

Variables using @ and @@ are variables used inside a class.

You're not inside a class on this line:

my_message = Message.new(@from, @to)

#4

Why would you want to be inside a class when creating an instance of it?


#6

You don't need to apologize. I ask questions to make people think, not to make them feel guilty :smile:.


#8

https://www.codecademy.com/en/courses/ruby-beginner-en-MFiQ6/3/3?curriculum_id=5059f8619189a5000201fbcb..its still not working.