This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Putting a Class in Foster Care
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Maybe you could call it “duck classing,” who knows. I think it fits. Subclassing any possible parent class that acts like a certain class. So, in MouseHole, I can swap out proxy backends I’m testing.
def MouseHole.ProxyServer( proxy_base )
Class.new( proxy_base ) do
attr_accessor :user_scripts, :temp_scripts
def initialize #.. and other overlaying methods
end
end
end
Pass in the base class and you get an anonymous class freshly built between the two.
server = MouseHole.ProxyServer( WEBrick::HTTPProxyServer ).new
Ah, railroading inheritance. It’s like foster parents. Which is better than multiple inheritance (aka custody battles.) RIght?