super.index gives error

M

MohsinHijazee

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
 
A

Arlen Cuss

[Note: parts of this message were removed to make it a legal post.]

Hi:

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
 
M

MohsinHijazee

[Note: parts of this message were removed to make it a legal post.]

Hi:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,284
Messages
2,571,411
Members
48,103
Latest member
MadieDeitz

Latest Threads

Top