Reputation: 2510
I have a local variable in my main program. Now i would llike to give it to a method so it can use it for it's work. What is the best way to do it? A Instance variable @test?
Upvotes: 0
Views: 336
Reputation: 13574
You can give that variable as a method parameter, as shown in the example below:
def main_program
my_variable = 3
other_method(my_variable)
end
def other_method(special_variable)
# do something with the special-variable
end
A nice read on how to define and call methods can be found in the Ruby programming wiki
Upvotes: 1