NAME prototype.rb URIS http://codeforpeople.com/lib/ruby/ http://rubyforge.org/projects/codeforpeople/ SYNOPSIS prototype.rb implements the prototype design pattern http://en.wikipedia.org/wiki/Prototype-based_programming for ruby WHY prototype based programming can look very nice ;-) EXAMPLES __________________________________________ ~ > cat samples/a.rb __________________________________________ require 'prototype' singleton = Prototype.new{ @a, @b = 40, 2 def answer() @a + @b end } p singleton.answer __________________________________________ ~ > ruby samples/a.rb __________________________________________ 42 __________________________________________ ~ > cat samples/b.rb __________________________________________ require 'prototype' DB = Prototype.new{ host 'localhost' port 4242 def connect() p [host, port] end } p DB p DB.host p DB.port DB.connect __________________________________________ ~ > ruby samples/b.rb __________________________________________ "localhost" 4242 ["localhost", 4242] __________________________________________ ~ > cat samples/e.rb __________________________________________ require 'prototype' proto = prototype{ @a = 40 @b = 2 } p(proto.a + proto.b) ~ > ruby -Ilib samples/e.rb 42 __________________________________________ ~ > cat samples/f.rb __________________________________________ require 'prototype' a = prototype{ attributes 'a' => 4, 'b' => 10, 'c' => 2 } b = prototype{ a 4; b 10; c 2 } c = prototype{ @a, @b, @c = 4, 10, 2 } [a, b, c].each{|obj| p(obj.a * obj.b + obj.c) } ~ > ruby -Ilib samples/f.rb 42 42 42 __________________________________________ ~ > cat samples/g.rb __________________________________________ require 'prototype' a = prototype b = prototype(a){ @a, @b, @c = 4, 10, 2 } a.extend{ def answer() a * b + c end } p b.answer ~ > ruby -Ilib samples/g.rb 42 DOCS see lib/*rb samples/*rb