Module: Extensional
- Includes:
- Enumerable
- Defined in:
- lib/extensional.rb
Overview
An Extensional Class collects its instances. See Class#make_extensional for the usage model.
Constant Summary collapse
- VERSION =
This Extensional implementation version.
'1.3.1'
Instance Method Summary collapse
-
#<<(instance) ⇒ Object
Adds an instance of this class to the class extent.
-
#clear ⇒ Object
Clears this class’s extent.
-
#each(&block) ⇒ Object
Calls block an each instance in this class’s extent.
-
#extent ⇒ Object
Returns this Extensional class’s Extent.
-
#for(*key) ⇒ Object
Returns the instance with the given key arguments, or nil if no association is found.
Instance Method Details
#<<(instance) ⇒ Object
Adds an instance of this class to the class extent.
32 33 34 |
# File 'lib/extensional.rb', line 32 def <<(instance) @extent << instance end |
#clear ⇒ Object
Clears this class’s extent.
42 43 44 |
# File 'lib/extensional.rb', line 42 def clear @extent.clear end |
#each(&block) ⇒ Object
Calls block an each instance in this class’s extent.
37 38 39 |
# File 'lib/extensional.rb', line 37 def each(&block) @extent.each(&block) end |
#extent ⇒ Object
Returns this Extensional class’s Extent.
14 15 16 |
# File 'lib/extensional.rb', line 14 def extent @extent end |
#for(*key) ⇒ Object
Returns the instance with the given key arguments, or nil if no association is found.
Raises NotImplementedError if the class extent does not implement associative access.
21 22 23 24 25 26 27 28 29 |
# File 'lib/extensional.rb', line 21 def for(*key) unless @extent.associative? then raise NotImplementedError.new("Associative access by key is not implemented for #{self}") end # extract the key argument from a key array with zero or one members; # if key has more than one member, the key remains an array of all arguments key = key.first if key.size == 1 @extent.find(key) end |