What does << do?

G

Gaba Luschi

Reading a sample program that says:
@rooms << Room.new(reference, name, description, connections)

What does the "<<" part do? Thanks!
 
S

Sebastian Bachmann

[Note: parts of this message were removed to make it a legal post.]

Hi,

imho << reads Room.new(reference, name, description, connections) _into_ @rooms

Regards
 
J

John Feminella

The answer is, "it depends on what @rooms is". In Ruby, (almost)
everything's an object, so when you write "@rooms << ...", you're
actually invoking the "<<" method on "@rooms".

If @rooms is an Array, for example, then << will append to the end of
the array, which is probably what's happening here.

~ jf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,352
Latest member
DianeKulik

Latest Threads

Top