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

user229044
  • 232,980
  • 40
  • 330
  • 338
Cassiano
  • 15
  • 3

1 Answers1

-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 ;)

katafrakt
  • 2,438
  • 15
  • 19
  • You missed the point, `super` cannot help here. That isn't how you invoke a method you're overwriting. – user229044 Sep 02 '16 at 20:14
  • 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. – katafrakt Sep 02 '16 at 20:20
  • 3
    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. – user229044 Sep 02 '16 at 20:21