So it's a variable that is automtically given to each instance of that
class right?
Not quite... it's a variable in the instance that it is declared. So,
if you put it in the 'initialize' method as seen in that example, it
will assign that variable for that instance when it is created.
So it's a variable that is automtically given to each instance of that
class right?
Not quite... it's a variable in the instance that it is declared. So,
if you put it in the 'initialize' method as seen in that example, it
will assign that variable for that instance when it is created.
-Jonathan Nielsen
So... it's a variable that can only be used in that instance and nowhere
else?
You can also just say @x, here, because puts will convert the objects it
receives into strings by calling the to_s method on them
puts "#{@x}"
puts @x.to_s
puts @x
In this case will all be the same, there is no need to interpolate strings
here.
At least in 1.9.1 this is true. I tried it in 1.8 and the last one outputted
"nil" which is odd, and the only way I can think of that would explain it is
that puts checks to see if the variable is nil before calling to_s, and
explicitly outputs "nil" if it is.
···
On Fri, Apr 2, 2010 at 2:15 PM, Tom Stone <s1ay3r44@gmail.com> wrote: