# Referring to previously overridden method without subclass

**URL:** <https://www.ruby-forum.com/t/referring-to-previously-overridden-method-without-subclass/133545>\
**Category:** Ruby\
**Created:** [April 1, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/referring-to-previously-overridden-method-without-subclass/133545 "2008-04-01T15:02:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [April 1, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/referring-to-previously-overridden-method-without-subclass/133545/1 "2008-04-01T15:02:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [April 1, 2008, 3:07pm UTC](https://www.ruby-forum.com/t/referring-to-previously-overridden-method-without-subclass/133545/2 "2008-04-01T15:07:58Z")

</div>

On Tue, Apr 1, 2008 at 3:02 PM, Oliver S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)

```

---

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [April 1, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/referring-to-previously-overridden-method-without-subclass/133545/3 "2008-04-01T15:11:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [April 1, 2008, 3:37pm UTC](https://www.ruby-forum.com/t/referring-to-previously-overridden-method-without-subclass/133545/4 "2008-04-01T15:37:13Z")

</div>

Thanks.
