Setup:
class Parent
def foo
bar()
end
def bar
# more stuff
end
end
class Child < Parent
def bar
# over riding bar
end
end
obj = Child.new
obj.foo
---
K, now naturally, due to inheritance this will call Parent#foo in
which it calls ''bar()''
My problem is this:
Why does it call Parent#bar instead of Child#bar? ... according to
inheritance and method overriding Parent#bar is replaced with
Child#bar ... so when Parent#foo calls some method named
''bar'', should
it not call Child#bar due to obj being an instance of Child??
Where am I going wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Brenton B wrote:> Why does it call Parent#bar instead of Child#bar? ... according to > inheritance and method overriding Parent#bar is replaced with > Child#bar ... so when Parent#foo calls some method named ''bar'', should > it not call Child#bar due to obj being an instance of Child??This question will get better results on the Ruby-talk mailing lists and newsgroups.> Where am I going wrong?What is your evidence that the parental bar() gets called? Post your question, with that addition, that to the Ruby group(s). -- Phlip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hmm ... good though, I''ll throw it over there. On Feb 21, 6:12 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Brenton B wrote: > > Why does it call Parent#bar instead of Child#bar? ... according to > > inheritance and method overriding Parent#bar is replaced with > > Child#bar ... so when Parent#foo calls some method named ''bar'', should > > it not call Child#bar due to obj being an instance of Child?? > > This question will get better results on the Ruby-talk mailing lists and newsgroups. > > > Where am I going wrong? > > What is your evidence that the parental bar() gets called? Post your question, > with that addition, that to the Ruby group(s). > > -- > Phlip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m a tool ... never mind got it going ... there was a mix up with alias_method, wasn''t setup the way I thought it was ... ugh. On Feb 21, 6:17 pm, Brenton B <brenton.bar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hmm ... good though, I''ll throw it over there. > > On Feb 21, 6:12 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Brenton B wrote: > > > Why does it call Parent#bar instead of Child#bar? ... according to > > > inheritance and method overriding Parent#bar is replaced with > > > Child#bar ... so when Parent#foo calls some method named ''bar'', should > > > it not call Child#bar due to obj being an instance of Child?? > > > This question will get better results on the Ruby-talk mailing lists and newsgroups. > > > > Where am I going wrong? > > > What is your evidence that the parental bar() gets called? Post your question, > > with that addition, that to the Ruby group(s). > > > -- > > Phlip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---