After learning how to write methods, we need to have a look at a concept called scopes.
In the following interactive exercise, we'll learn what this means.
What's the output of following script:
greeting = "Hello!" puts greeting
def greet_in_french greeting = "Bonjour!" puts greeting end greet_in_french
greeting = "Hello!" def greet_in_czech greeting = "Ahoj!" puts greeting end greet_in_czech puts greeting
greeting = "Hello!" def greet_in_japanese greeting = "こんにちは" # Kon'nichiwa puts greeting end greeting = "Good day!" greet_in_japanese puts greeting
こんにちは Good day!
greeting = "Hei der!" def greet_in_norwegian puts greeting end greet_in_norwegian
There is a way how we can read variables from a global scope.
This is covered in a different lesson. 👷♀️
What questions do you have?