Referring to previously overridden method without subclass

I’m trying to debug a bit of code. I want to output all the parameters
passed to PGconn#exec each time it is called but still have the method
function as it should.

I tried this:

class PGconn
def exec(*args)
puts “exec: #{args}”
super *args
end
end

But super ends up calling Kernel#exec, how can I refer to the version of
exec before I added the puts enhancement?

On Tue, Apr 1, 2008 at 3:02 PM, Oliver S.
[email protected] wrote:

I’m trying to debug a bit of code. I want to output all the parameters
passed to PGconn#exec each time it is called but still have the method
function as it should.

I tried this:

class PGconn

  • alias_method :old_exec, :exec

def exec(*args)
puts “exec: #{args}”

  •   super *args
    
  •  old_exec(*args)

Oliver S. wrote:

I’m trying to debug a bit of code. I want to output all the parameters
passed to PGconn#exec each time it is called but still have the method
function as it should.

I tried this:

class PGconn

alias old_exec exec

def exec(*args)
puts “exec: #{args}”

     old_exec(*args)

end
end

Regards,

Michael

Thanks.

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