Reference an undefined variable in a method : Variable scope « Language Basics « Ruby






Reference an undefined variable in a method


def basic_method
  puts x
end

x = 10
basic_method

 








Related examples in the same category

1.items declared in those methods are restricted to those methods.
2.have two local variables with the same name but in different scopes
3.using only local variables
4.Local Variables versus Methods