Your second example initializes @blah
as a class variable. It wouldn't be directly accessible (it'd need a class accessor) and would be the same across all instances of a class.
Instance variables are private-ish by nature, though you can get access to them with @foo.instance_variable_get("@blah")
. Conventionally, if you want to access a @blah
instance variable, you would add an accessor.
class Shape
attr_accessor :blah
end
That would let you say, for example, shape = Shape.new; shape.blah = "whee"; puts shape.blah
(and you'd get "whee").