B
Bryan Richardson
Hello all,
I'm having some trouble with extending an existing Ruby class in order
to add functionality. Here's some example code:
class Graph
....
....
def subgraph(*args)
graph = self.new
....
....
return graph
end
end
class AwesomeGraph < Graph
....
....
def do_something
....
....
end
end
g = AwesomeGraph.new
a = g.subgraph(g.nodes)
a.do_something // ERROR! No Graph#do_something exists!
I was hoping 'self.new' would take into account the derived class used
upon creation, but it doesn't.
Any suggestions?
I'm having some trouble with extending an existing Ruby class in order
to add functionality. Here's some example code:
class Graph
....
....
def subgraph(*args)
graph = self.new
....
....
return graph
end
end
class AwesomeGraph < Graph
....
....
def do_something
....
....
end
end
g = AwesomeGraph.new
a = g.subgraph(g.nodes)
a.do_something // ERROR! No Graph#do_something exists!
I was hoping 'self.new' would take into account the derived class used
upon creation, but it doesn't.
Any suggestions?