What is the use of global variable $ in Ruby?

Questions by nancyphilips   answers by nancyphilips

Showing Answers 1 - 0 of 0 Answers

Manikandan Mca

  • Aug 18th, 2007
 

If you declare one variable as global we can access any where, where as class variable visibility only in the class 
Example
class Test
def h
  $a = 5
  @b = 4
 
while $a > 0
puts $a
$a= $a - 1
end
end
end
test = Test.new
test.h
puts $a                     # 5
puts @b                    #nil

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions