In your case, description
is just a local variable. You can change this area with the special characters @
, @@
, $
:
a = 5 defined? a => "local-variable" @a = 5 defined? @a => "instance-variable" @@a = 5 defined? @@a => "class variable" $a = 5 defined? $a => "global-variable"
For your purpose, I think it can be used this way.
class User def initialize(description) @description = description end def print puts @description end end obj = User.new("I am User") obj.print
source share