From: ara.t.howard@... Date: 2006-07-13T00:07:42+09:00 Subject: Re: prototype design pattern On Wed, 12 Jul 2006, Berger, Daniel wrote: > Hm, it's not at > http://wiki.rubygarden.org/Ruby/page/show/ExampleDesignPatternsInRuby http://en.wikipedia.org/wiki/Prototype-based_programming > Anyway, it looks to me like some combination of .clone plus a factory. I'm > not sure there's any real savings in Ruby to doing things this way, but I'd > be happy to be proved wrong. hi daniel- savings is only keystrokes. but it can very elegant looking and, these days, ruby coding bores me unless it looks good too - solving problems is just too easy in it to provide enough challenge! ;-) take this code for example: fortytwo :~/eg/ruby/prototype > cat a.rb require 'prototype' singleton = Prototype.new{ @a, @b = 40, 2 def answer() @a + @b end } p singleton.answer fortytwo :~/eg/ruby/prototype > ruby a.rb 42 fortytwo :~/eg/ruby/prototype > cat b.rb require 'prototype' DB = Prototype.new{ host 'localhost' port 4242 def connect() 'do something' end def inspect() [host, port].join ':' end } p DB p DB.host p DB.port fortytwo :~/eg/ruby/prototype > ruby b.rb localhost:4242 "localhost" 4242 do you like the look of it? i'll post my impl in a follow-up. cheers. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama