< :the previous in number
^ :the list in numerical order
> :the next in number
P :the previous (in thread)
N :the next (in thread)
|<:the top of this thread
>|:the next thread
^ :the parent (reply-to)
_:the child (an article replying to this)
>:the elder article having the same parent
<:the youger article having the same parent
---:split window and show thread lists
| :split window (vertically) and show thread lists
~ :close the thread frame
.:the index
..:the index of indices
Hei Chuck,
that's exactly what i was trying to avoid. While I'm at it, let me be
more specific about my problem, which is actually not just printing out
text to the console but changing the state of the newly created
instance:
class Parent
attr_reader :test_value
def initialize
@test_value = "from parent"
end
end
class Child < Parent
def initialize
p @test_value
end
end
child = Child.new
this should print out "from parent"
--
Andrea Dallera
http://github.com/bolthar/freightrain
http://usingimho.wordpress.com
On Mon, 2010-03-15 at 23:32 +0900, Chuck Remes wrote:
> On Mar 15, 2010, at 9:13 AM, Andrea Dallera wrote:
> > Hi everybody,
> >
> > given the following situation:
> >
> > class Parent
> >
> > def initialize
> > print "magic\n"
> > end
> >
> > end
> >
> > class Child < Parent
> >
> > def initialize
> > print "more magic\n"
> > end
> >
> > end
> >
> > child = Child.new
> >
> > is there a way in which i can get "magic" and "more magic" as the
> > output, without having to add super to the child class's constructor? I
> > was thinking about overriding the class method "new" but i really didn't
> > get anything to work up to now.
>
> Use the #super keyword to call the superclass.
>
>
> class Parent
> def initialize
> print "magic\n"
> end
> end
>
> class Child < Parent
> def initialize
> super
> print "more magic\n"
> end
> end
>
> child = Child.new
>
> ----------
>
> cremes$ ruby a.rb
> magic
> more magic
>
> cr
>
>