T
transfire
Jan Molic recently contacted me about a slighlty modified version of
his OrderedHash class that I distribute in Facets, the Dictionary
class. There are a few variations of this class initself and Jan
originally provided these via a subclass. I, on the other, thought
alternate initializers would be better.
Which is the best approach?
Ex.
class AutoOrderHash < OrderedHash
def new(*args)
super(*args){ |h,k| h[k] = self.class.new }
end
end
vs.
class OrderHash
def self.auto(*args)
new(*args){ |h,k| h[k] = self.class.new }
end
end
Thanks,
T.
his OrderedHash class that I distribute in Facets, the Dictionary
class. There are a few variations of this class initself and Jan
originally provided these via a subclass. I, on the other, thought
alternate initializers would be better.
Which is the best approach?
Ex.
class AutoOrderHash < OrderedHash
def new(*args)
super(*args){ |h,k| h[k] = self.class.new }
end
end
vs.
class OrderHash
def self.auto(*args)
new(*args){ |h,k| h[k] = self.class.new }
end
end
Thanks,
T.