From: "ara.t.howard" Date: 2007-06-06T06:45:16+09:00 Subject: Re: [ANN] prototype-2.0.0 On Jun 5, 2007, at 2:19 PM, James Edward Gray II wrote: > On Jun 5, 2007, at 3:03 PM, ara.t.howard wrote: > >> >> On Jun 5, 2007, at 12:55 PM, Victor Zverok Shepelev wrote: >> >>> * Does anybody uses it in real projects? I mean, does prototype- >>> based >>> approach in not prototype-based language have proved to be >>> useful? The >>> question is not about "throw the library away", but about "who >>> can say, what >>> features in library are useful", "who can recommend library for >>> some tasks?" >> >> example >> >> Config = Object.prototype{ >> YAML.load(IO.read('config')).each do |key, value| >> attribute key => value >> end >> } >> >> p Config.host >> p Config.port > > Which is significantly better than: > > require "ostruct" > Config = OpenStruct.new( > File.open("config") { |file| YAML.load(file) } > ) > > ? yes, i think so: cfp:~ > cat a.rb require 'rubygems' require 'prototype' require 'ostruct' require 'yaml' hash = { :id => 42, :send => 'ara.t.howard@gmail.com', :class => 'first', } running 'prototype' do config = prototype.configured hash p config.id p config.send p config.class end running 'ostruct' do config = OpenStruct.new hash p config.id p config.send p config.class end BEGIN { def running name puts "<======== #{ name } ========" begin yield rescue => e m, c, b = e.message, e.class, e.backtrace.join("\n") puts "#{ m }(#{ c })\n#{ b }" ensure puts end end } cfp:~ > ruby a.rb <======== prototype ======== 42 "ara.t.howard@gmail.com" "first" <======== ostruct ======== a.rb:21: warning: Object#id will be deprecated; use Object#object_id 125270 no method name given(ArgumentError) a.rb:22:in `send' a.rb:22 a.rb:31:in `running' a.rb:19 realize too that using a prototype for a Config class is but a tiny tiny sample of where it might benefit someone. anywhere you have a singleton or a copy constructor it's worth considering. i'll have some magnetic code posted soon - you can look at that for an example of grittier prototype use. kind regards. -a -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama