Getting the parameters from a method - 1.9.x vs 1.8.x

I see in the Ruby documentation for 1.9.2 that there is:

meth.parameters → array

returns the parameter information of this method

For class UnboundMethod.

Does anyone know how to do so in Ruby 1.8.7 ?

I lately wanted to get all parameters to a method, but without using a
hash. (With a hash, it is easy.)

def foo(a, b = ‘foo’,c = ‘bar’, d = ‘faa’)
puts ‘Hello from method foo. Try to find out my parameters!’


If this is not possible in Ruby 1.8.7 I may have found another reason to
finally switch to 1.9.x even though the Encoding issues are annoying to
deal with for me in 1.9.x (1.8.x gives me no problem here).

Would getting the arity suffice?

one way is to use parse tree and ruby2ruby: klass, method 



I think that ree also has the #source_location method on Method objects,
as well, but don’t quote me on that.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs