From: "ara.t.howard" Date: 2007-06-06T05:03:09+09:00 Subject: Re: [ANN] prototype-2.0.0 On Jun 5, 2007, at 12:55 PM, Victor Zverok Shepelev wrote: > From: ara.t.howard [mailto:ara.t.howard@gmail.com] > Sent: Tuesday, June 05, 2007 6:33 AM > > >> NAME >> prototype.rb >> > > Several small questions about the library: > > * Does cloned object has some connections with it's prototype (as > per Io: > "prototype is something knowing how to process messages I don't know") > yes. if one does clone = Object.prototype{ @a = 42 }.clone the clone has a #a method from parent and @a instance var if it's own > * If so, can object's prototype be changed dynamically? (I mean, > b.proto = > c) > no. but they can be extended proto = Object.prototype proto.prototyping do @a = 42 def a() @a end end > * And what about Io-like "prototype is context for code blocks?": > > block = lambda{puts a + b} > > block.call #=> undefined local variable or method `a' > > p = Prototype.new{ > @a = 40 > @b = 2 > } > > block.proto = p > > bloc.call #=> 42 > sortof. cfp:~ > cat a.rb require 'prototype' block = lambda{ puts a + b } proto = Object.prototype proto.prototyping do a 40 b 2 c &block end proto.c cfp:~ > ruby a.rb 42 i think your exact example would be quite easy to impliment > BTW, Markaby uses complicated hack to "setup context variables, while > building HTML" - which is very close to the above example. > check out prototype.rb impl - it's very clean imho. nothing is off limits - you can have attribute 'id', 'name', 'object_id', etc and everything works. > * 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 i'm using it in several project where one might instead use a singleton. the advantage prototype gives you is basically that you can have a hierarchy of singletons, each inheriting state and behavior from it's parent. i'm currently building a model->view (no controller) system for rails called 'magnetic' that hinges upon the ability to specify a hierarchy of properties and behavior over those properties and also that requires that each set of properties be a singleton (for performance reasons) and it's filling that roll nicely. look for a release in the next few weeks. 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