Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Methods defined with #define_method have no parameters #2204

ryanong opened this Issue Mar 14, 2013 · 2 comments


None yet
3 participants

ryanong commented Mar 14, 2013

class Foo
  define_method(:bar) { |arg| }

Foo.instance_method(:bar).parameters #=> [[:req, :arg]]
Foo.new.method(:bar).parameters #=> []

Kind of fascinating really.
I am making a new mocking library and I use some gnarly hacks using parameters inspection to detect if the method is stubbed.

Kernel#method uses Rubinius.find_method(self, name)

And for dynamic methods it returns a Rubinius::BlockEnvironment::AsMethod

AsMethod#parameters is not defined so when it is sent into Method it just returns []

However when you use Module#instance_method it sends the AsMethod object into an UnboundMethod which converts #local_names into the correct #parameters format.

This conversion code for local_names is nearly the same as what is found in Proc. In MRI blocks for the most part are almost always a Proc except when a block is sent to #define_method or #define_singleton_method where it is turned into a Lambda.

@ghost ghost assigned YorickPeterse Mar 27, 2013


dbussink commented Mar 31, 2013

Looks like this is already fixed with the work of @YorickPeterse. We should probably make sure that this behavior is covered with specs though, don't know if they have been added for this cases when Method#parameters was fixed.


dbussink commented Apr 12, 2013

I'm closing this one, since this bug has been fixed by refactoring Method#parameters

@dbussink dbussink closed this Apr 12, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment