have two local variables with the same name but in different scopes : Variable scope « Language Basics « Ruby






have two local variables with the same name but in different scopes



def basic_method
  x = 50
  puts x
end

x = 10
basic_method
puts x

 








Related examples in the same category

1.items declared in those methods are restricted to those methods.
2.Reference an undefined variable in a method
3.using only local variables
4.Local Variables versus Methods