using only local variables : Variable scope « Language Basics « Ruby






using only local variables


def returnFoo
  bar = "Ramone, bring me my cup."
  return bar
end

puts returnFoo
# But this code is not allowed:

def returnFoo
  bar = "Ramone, bring me my cup."
  return bar
end

puts bar

 








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.have two local variables with the same name but in different scopes
4.Local Variables versus Methods