instance variable
@var = "I am instance var"
class C
def examine_var
puts @var
end
end
c = C.new
c.examine_var
global variable
$gvar = "I am a global var"
class C
def examin_global
puts $gvar
end
end
c = C.new
c.examin_global
class Person
def whole_name
n = $first_name + " "
n << "#{middle_name} " if $middle_name
n << $last_name
end
end
david = Person.new
$first_name = "Pooya"
$last_name = "Ghobadi"
puts david.whole_name
Top comments (0)