The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Putting a Class in Foster Care

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Putting a Class in Foster Care Posted: Oct 4, 2005 2:55 PM
Reply to this message Reply

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
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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?

Read: Putting a Class in Foster Care

Topic: LEDs make prettier applications Previous Topic   Next Topic Topic: Might attend RubyConf

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use