items declared in those methods are restricted to those methods. : Variable scope « Language Basics « Ruby






items declared in those methods are restricted to those methods.


text = "No worries."
    
def greeting()
  text = "No problems."
  puts text
end

greeting

puts text

 








Related examples in the same category

1.Reference an undefined variable in a method
2.have two local variables with the same name but in different scopes
3.using only local variables
4.Local Variables versus Methods