1

I'm trying to prepend a binding.remote_pry to all methods from all classes of my application for a test environment.

I try this:

classes = [] ObjectSpace.each_object { |o| classes << o if o.class == Class } classes.each do |classe| classe.methods.each do |method_name| classe.class_eval do define_method(method_name.to_sym) do @@bindings ||= [] @@bindings << Thread.new {binding.remote_pry} super end end end end 

But I don't know how to call the super of each method inside define_method Am I trying to do something too much crazy here? There is another way? Thanks in advance

5
  • Definitely something crazy. What's the problem with calling super, again? Commented Sep 2, 2016 at 20:09
  • FYI: classes = ObjectSpace.each_object.select { |o| o.class == Class } Commented Sep 2, 2016 at 20:11
  • RuntimeError: implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. Commented Sep 2, 2016 at 20:15
  • @Cassiano See the linked duplicate. It outlines many ways of accomplishing this. Commented Sep 2, 2016 at 20:16
  • Thanks a lot. I will search harder next time. Commented Sep 2, 2016 at 20:26

1 Answer 1

-1

You should call it with explicit empty argument list, otherwise super tries to pass arguments from original method, which does not work with methods defined by define_method. Just do:

super() 

and you should be fine ;)

Sign up to request clarification or add additional context in comments.

3 Comments

You missed the point, super cannot help here. That isn't how you invoke a method you're overwriting.
Well, it answers question "How can I call 'super' from 'define_method'?" so I don't see how it's missing the point. OP would get another error which will steer him at the direction of how to accomplish his goal. but of course suit yourself with a downvote.
You're not helping, if you give people advice that points them in the wrong direction without actually explaining why the attempted approach won't work. Please don't add answers if you have no faith that it will actually solve the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.