Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   super.index gives error (http://www.velocityreviews.com/forums/t848248-super-index-gives-error.html)

MohsinHijazee 02-19-2008 10:32 AM

super.index gives error
 
Hello!
I'm having a strange problem.

class Super

def index
puts "some code"
end
end

class Base < Super

def index
super.index() # Says you super is nil! nil.index and an
error. What might be wrong?
end
end

Arlen Cuss 02-19-2008 10:38 AM

Re: super.index gives error
 
[Note: parts of this message were removed to make it a legal post.]

Hi:

On Feb 19, 2008 9:34 PM, MohsinHijazee <mohsinhijazee@gmail.com> wrote:

> Hello!
> I'm having a strange problem.
>
> class Super
>
> def index
> puts "some code"
> end
> end
>
> class Base < Super
>
> def index
> super.index() # Says you super is nil! nil.index and an
> error. What might be wrong?
> end
> end
>
>

irb(main):001:0> class Super
irb(main):002:1> def index
irb(main):003:2> puts "some code"
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> class Sub < Super
irb(main):007:1> def index
irb(main):008:2> super
irb(main):009:2> end
irb(main):010:1> end
=> nil
irb(main):011:0> Sub.new.index
some code
=> nil
irb(main):012:0>

Technically, Super is also the `base' class, so I named it Sub. Just use
`super' -- super calls the method of the same name in the superclass.

HTH
Arlen


MohsinHijazee 02-19-2008 10:49 AM

Re: super.index gives error
 
On Feb 19, 3:38 pm, Arlen Cuss <cel...@sairyx.org> wrote:
> [Note: parts of this message were removed to make it a legal post.]
>
> Hi:
>
> On Feb 19, 2008 9:34 PM, MohsinHijazee <mohsinhija...@gmail.com> wrote:
>
>
>
> > Hello!
> > I'm having a strange problem.

>
> > class Super

>
> > def index
> > puts "some code"
> > end
> > end

>
> > class Base < Super

>
> > def index
> > super.index() # Says you super is nil! nil.index and an
> > error. What might be wrong?
> > end
> > end

>
> irb(main):001:0> class Super
> irb(main):002:1> def index
> irb(main):003:2> puts "some code"
> irb(main):004:2> end
> irb(main):005:1> end
> => nil
> irb(main):006:0> class Sub < Super
> irb(main):007:1> def index
> irb(main):008:2> super
> irb(main):009:2> end
> irb(main):010:1> end
> => nil
> irb(main):011:0> Sub.new.index
> some code
> => nil
> irb(main):012:0>
>
> Technically, Super is also the `base' class, so I named it Sub. Just use
> `super' -- super calls the method of the same name in the superclass.
>
> HTH
> Arlen


Thank you very much! The problem is solved


All times are GMT. The time now is 03:22 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.