# I don't know "super".... Sorry for my ignorance

**URL:** <https://www.ruby-forum.com/t/i-dont-know-super-sorry-for-my-ignorance/167494>\
**Category:** Rails\
**Created:** [May 8, 2009, 1:06pm UTC](https://www.ruby-forum.com/t/i-dont-know-super-sorry-for-my-ignorance/167494 "2009-05-08T13:06:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [May 8, 2009, 1:06pm UTC](https://www.ruby-forum.com/t/i-dont-know-super-sorry-for-my-ignorance/167494/1 "2009-05-08T13:06:26Z")

</div>

Hi All,

Today, when I debug, I found that I don’t understand a very basic  
function “super”.

`
class User < ActiveRecord::Base
def self.columns
puts “here…”
@ret = super
return @ret
end
end
`

This return only one line of “here…”. It is very  
fine. However, when I called

My codes are:  
``

class User \< ActiveRecord::Base  
def self.columns  
puts “here…”  
super  
end

end

The return is what I expected - a list of columns in User, but this  
display 18 lines of “here…” in the console (the  
length of “columns” of my User is 17.

What is the difference between the two super call?

Thanks much!  
Arthur

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [May 8, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/i-dont-know-super-sorry-for-my-ignorance/167494/2 "2009-05-08T20:43:27Z")

</div>

> @ret = super  
> `
> The return is what I expected - a list of columns in User, but this
> display 18 lines of “here…” in the console (the
> length of “columns” of my User is 17.`
> 
> What is the difference between the two super call?

These two methods should both print the line  
“here…” to standard output before they return an  
array of column objects. I’m not sure why you’re getting different  
results. Note that the super keyword has different semantics in Ruby  
than for example Java – I’d suggest consulting the Pickaxe or Ruby  
for Rails if you’re confused about its behaviour.

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [May 10, 2009, 6:43am UTC](https://www.ruby-forum.com/t/i-dont-know-super-sorry-for-my-ignorance/167494/3 "2009-05-10T06:43:09Z")

</div>

Hi BjÃ¸rn,

thanks for your direction.

The question is created by one bug in my program - I wanna use the super  
to in my overriding “find\_by\_email” functions. I found that I can  
override it the first time, but afterwards, the super class method is  
called instead (skipped my overriding code totally).

Now, I solved my original problem and bet that the “find\_by\_email”  
should be method\_missing call, and the Rails remember the super class  
call afterwards.

Is my estimation is correct?

In anyway, I still cannot answer the 1 time output and 18 times outputs  
difference, I am after the 2nd methods indeed was triggered 18times.

Thanks!

BjÃ¸rn Arild MÃ¦land wrote:

> > @ret = super  
> > `
> > The return is what I expected - a list of columns in User, but this
> > display 18 lines of “here…” in the console (the
> > length of “columns” of my User is 17.`
> > 
> > What is the difference between the two super call?
> 
> These two methods should both print the line  
> “here…” to standard output before they return an  
> array of column objects. I’m not sure why you’re getting different  
> results. Note that the super keyword has different semantics in Ruby  
> than for example Java – I’d suggest consulting the Pickaxe or Ruby  
> for Rails if you’re confused about its behaviour.
