Methods may or may not have access to certain variables, depending on the circumstances. Here are some examples:
def say_hello
message = "hello"
return message
end
p say_hello # => "hello"
message = "hello"
def say_hello
return message
end
p say_hello # => in `say_hello': undefined local variable or method `message' for main:Object (NameError)
@message = "hello"
def say_hello
return @message
end
p say_hello # => "hello"
message = "hello"
def say_hello(input_message)
return input_message
end
p say_hello(message) # => "hello