Sorry for such a basic OOP type question in advance.
How do I emulate Ruby's _super()_ for a subclassed object's constructor?
* When I create a _child_ object via _newChild()_ , I want the childs parent
constructor _newParent()_ to be invoked to define the parent specific
fields.
* The documentation seems to indicate that **procCall()** might be part of
the solution.
_BTW: I have no idea why RST is bolding the " When I create a ..." line
above???_
type
ParentObj* = ref object of RootObj
parentField: int
ChildObj* = ref object of ParentObj
childField: string
proc newParent*(value: int): ParentObj =
new result
result.parentField = value
# This works... but requires needless creation of a separate parent.
proc newChild*(value: string): ChildObj =
let parent = newParent 123 # *** How to eliminte this ***
new result
result.parentField = parent.parentField
result.childField = value
var child = newChild "ABC"
echo "child parentField: ", child.parentField
echo "child childField: ", child.childField
Run