[ANN] prototype-0.1.0

A

ara.t.howard

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


-a
 
J

Jeremy Tregunna

I think maybe you took what I was saying for more than my intended
point. I was only sayng that I think the use of the word
"Prototype" in
Ara's implementation conveys too much the prior notions of class-based
OOP, and that the more general term, 'Object' would be more fitting.
Then I was trying to explain why.

Ah, okay, sorry.
Interestingly, your example uses the very word 'Object'.

Well, in the Io programming language, to which my example was written
in, the root object is called of all things, "Object", just like
Ruby, Smalltalk, Java, and countless other OO languages.

--
Jeremy Tregunna
(e-mail address removed)


"One serious obstacle to the adoption of good programming languages
is the notion that everything has to be sacrificed for speed. In
computer languages as in life, speed kills." -- Mike Vanier
 
T

transfire

Jeremy said:
Well, in the Io programming language, to which my example was written
in, the root object is called of all things, "Object", just like
Ruby, Smalltalk, Java, and countless other OO languages.

:D

Why do they never choose "Thing"? ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top