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.

http://www.ruby-doc.org/core/classes/UnboundMethod.html

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!’
end

method(:foo).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:

ParseTree.new.process(ParseTree.translate( klass, method 

).assoc(:scope).assoc(:block))

ref

https://github.com/rdp/arguments/blob/master/lib/arguments/mri.rb#L7

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