ruby on rails - How can I get instance method parameters? -
i'm trying retrieve parameters couple instance methods. idiomatic ruby way so:
class def test(id) puts id end end a.instance_method(:test).parameters #=> [[:req, :id]]
this approach works of time, strange returns methods , have no idea why.
module events class repository def find(id) #code end def delete(id) #code end end end events::repository.instance_method(:find).parameters #=> [[:req, :id]] events::repository.instance_method(:delete).parameters #=> [[:rest, :args], [:block, :block_for_method]]
is ruby bug?
note: i'm typing above rails console.
i don't know why getting behavior, if answer questions earlier comment can figure out.
however, answer question can not bug in ruby. here example of small ruby program give same kind of output getting:
module x def delete(*args, &block) end end class y prepend x end class y # reopen existing class def delete(x) end end p y.instance_method(:delete) # => #<unboundmethod: y(x)#delete> p y.instance_method(:delete).parameters # => [[:rest, :args], [:block, :block]]
Comments
Post a Comment