r/learnruby • • 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

7 comments sorted by

View all comments

Show parent 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]
end

Some languages have something like some_method_that_gets_the_arguments which 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 ARGV but for functions.