[ANN] Updateable 0.0.3

J

John W. Long

This is the first public release of a very, very small project I've been
developed at work. I call it Updateable. By mixing in the Updateable
module into a class you can easily update the attributes of the class
with a hash:

require 'updateable'

class TestObject
include Updateable

attr_accessor :a, :b, :c

def initialize(options = {})
update(options)
end
end

o = TestObject.new:)a => 1, :b => 2, :c => 3)
puts "#{o.a}#{o.b}#{o.c}" #=> '123'

o.update:)a => 'a', :b => 'b', :c => 'c')
puts "#{o.a}#{o.b}#{o.c}" #=> 'abc'

Download:
http://johnwlong.com/downloads/iblp-mixins-0.0.3/lib/updateable.rb

Tests:
http://johnwlong.com/downloads/iblp-mixins-0.0.3/test/unit/updateable_test.rb

Updateable is currently part of another small project which can be
downloaded here:

http://johnwlong.com/downloads/iblp-mixins-0.0.3.tgz
 
F

Francis Hwang

Interesting. Is there a particular kind of use that inspired you to
write this module? Or is it just that you'd rather condense four lines
of attribute assignment into one?

This is the first public release of a very, very small project I've
been developed at work. I call it Updateable. By mixing in the
Updateable module into a class you can easily update the attributes of
the class with a hash:

require 'updateable'

class TestObject
include Updateable

attr_accessor :a, :b, :c

def initialize(options = {})
update(options)
end
end

o = TestObject.new:)a => 1, :b => 2, :c => 3)
puts "#{o.a}#{o.b}#{o.c}" #=> '123'

o.update:)a => 'a', :b => 'b', :c => 'c')
puts "#{o.a}#{o.b}#{o.c}" #=> 'abc'

Download:
http://johnwlong.com/downloads/iblp-mixins-0.0.3/lib/updateable.rb

Tests:
http://johnwlong.com/downloads/iblp-mixins-0.0.3/test/unit/
updateable_test.rb

Updateable is currently part of another small project which can be
downloaded here:

http://johnwlong.com/downloads/iblp-mixins-0.0.3.tgz

Francis Hwang
http://fhwang.net/
 

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

[ANN] Defaultable 0.0.3 0
[ANN] threadify-0.0.3 0
[ANN] bj-0.0.3 0
[ANN] dike-0.0.3 2
[ANN] Net::SSH 0.0.3 18
[ANN] gmailer 0.0.3 3
[ANN] prototype-1.0.0 0
[ANN] dirwatch-0.0.3 0

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top