Class: Jinx::Associative
Overview
An Associative object implements a #[] method.
Direct Known Subclasses
Instance Method Summary collapse
-
#[](key) ⇒ Object
The associated object.
-
#initialize {|key| ... } ⇒ Associative
constructor
A new instance of Associative.
-
#writer {|key| ... } ⇒ Associative
A new Associative with a
[]=
writer method.
Constructor Details
#initialize {|key| ... } ⇒ Associative
Returns a new instance of Associative.
7 8 9 |
# File 'lib/jinx/helpers/associative.rb', line 7 def initialize(&accessor) @accessor = accessor end |
Instance Method Details
#[](key) ⇒ Object
Returns the associated object.
13 14 15 |
# File 'lib/jinx/helpers/associative.rb', line 13 def [](key) @accessor.call(key) end |
#writer {|key| ... } ⇒ Associative
Returns a new Associative with a []=
writer method.
20 21 22 |
# File 'lib/jinx/helpers/associative.rb', line 20 def writer(&writer) Writable.new(self, &writer) end |