README in attributes-3.2.0 vs README in attributes-3.3.0
- old
+ new
@@ -1,28 +1,34 @@
NAME
-
attributes.rb
-URIS
+INSTALL
+ gem install attributes
+URIS
http://rubyforge.org/projects/codeforpeople/
http://codeforpeople.com/lib/ruby
SYNOPSIS
+ attributes.rb provides a set of attr_* like method with several user
+ friendly additions. attributes.rb is similar to the traits.rb package but
+ sacrifices a few features for simplicity of implementation: attributes.rb is
+ only 42 lines of code.
- attributes.rb provides an attr_* like method will several user friendly
- additions. attributes.rb is similar to the traits.rb package but sacrafices
- a few features for simplicity of implementation: attributes.rb is only 42
- lines of code.
-
the implimentation of attributes.rb borrows many of the best ideas from the
metakoans.rb ruby quiz
http://www.rubyquiz.com/quiz67.html
in particular the solutions of Christian Neukirchen and Florian Gross.
+HISTORY
+ 3.3.0
+
+ moved to an instance variable-less model using an module level closure for
+ the attributes list
+
SAMPLES
<========< samples/a.rb >========>
~ > cat samples/a.rb
@@ -50,14 +56,13 @@
o.attribute 'answer' => 42
p o.answer
~ > ruby samples/a.rb
- samples/a.rb:5:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
- def attributes *a &b
- ^
- ./lib/attributes.rb:64: syntax error from samples/a.rb:5
+ 42
+ "forty-two"
+ 42
<========< samples/b.rb >========>
~ > cat samples/b.rb
@@ -79,14 +84,12 @@
p c.a
p c.b
~ > ruby samples/b.rb
- samples/b.rb:6:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
- def attributes *a &b
- ^
- ./lib/attributes.rb:64: syntax error from samples/b.rb:6
+ 42
+ 42.0
<========< samples/c.rb >========>
~ > cat samples/c.rb
@@ -104,14 +107,11 @@
c.x = c.y + c.z
p c.x
~ > ruby samples/c.rb
- samples/c.rb:4:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
- def attributes *a &b
- ^
- ./lib/attributes.rb:64: syntax error from samples/c.rb:4
+ 42
<========< samples/d.rb >========>
~ > cat samples/d.rb
@@ -151,10 +151,37 @@
c.x 'forty-two'
p c.x
~ > ruby samples/d.rb
- samples/d.rb:7:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
- def attributes *a &b
- ^
- ./lib/attributes.rb:64: syntax error from samples/d.rb:7
+ ["x", "y", "z"]
+ {"x"=>0, "y"=>1, "z"=>2}
+ "forty-two"
+
+
+ <========< samples/e.rb >========>
+
+ ~ > cat samples/e.rb
+
+ #
+ # my favourite element of attributes is that getters can also be setters.
+ # this allows incredibly clean looking code like
+ #
+ require 'attributes'
+
+ class Config
+ attributes %w( host port)
+ def initialize(&block) instance_eval &block end
+ end
+
+ conf = Config.new{
+ host 'codeforpeople.org'
+
+ port 80
+ }
+
+ p conf
+
+ ~ > ruby samples/e.rb
+
+ #<Config:0x220b0 @port=80, @host="codeforpeople.org">