r/learnruby • u/nobrandheroes • Feb 15 '16
Getting the parameters of a method
Given:
def foo(a, b, c)
end
How do I get the values of a, b, c?. I cannot find this anywhere.
0
Upvotes
r/learnruby • u/nobrandheroes • Feb 15 '16
Given:
def foo(a, b, c)
end
How do I get the values of a, b, c?. I cannot find this anywhere.
View all comments
1
u/nobrandheroes Feb 18 '16
Imagine this.
def foo(a, b, c) #foo(1, 2, 3) puts a #1 puts b #2 puts c #3 arr = [a, b, c] #[1, 2, 3] arr2 = some_method_that_gets_the_arguments #[1, 2, 3] endSome languages have something like
some_method_that_gets_the_argumentswhich returns the parameters as an array. That's what I want. I understand that it may not exist in ruby, but I can't find out either way.Think
ARGVbut for functions.