Class: Rinda::Tuple
- Inherits:
-
Object
- Object
- Rinda::Tuple
- Defined in:
- lib/rinda2/rinda.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#[](k) ⇒ Object
Accessor method for elements of the tuple.
-
#each ⇒ Object
Iterate through the tuple, yielding the index or key, and the value, thus ensuring arrays are iterated similarly to hashes.
-
#fetch(k) ⇒ Object
Fetches item
k
from the tuple. -
#initialize(ary_or_hash) ⇒ Tuple
constructor
Creates a new Tuple from
ary_or_hash
which must be an Array or Hash. -
#size ⇒ Object
The number of elements in the tuple.
-
#value ⇒ Object
Return the tuple itself.
Constructor Details
#initialize(ary_or_hash) ⇒ Tuple
Creates a new Tuple from ary_or_hash
which must be an Array or Hash.
16 17 18 19 20 21 22 |
# File 'lib/rinda2/rinda.rb', line 16 def initialize(ary_or_hash) if hash?(ary_or_hash) init_with_hash(ary_or_hash) else init_with_ary(ary_or_hash) end end |
Instance Method Details
#[](k) ⇒ Object
Accessor method for elements of the tuple.
34 35 36 |
# File 'lib/rinda2/rinda.rb', line 34 def [](k) @tuple[k] end |
#each ⇒ Object
Iterate through the tuple, yielding the index or key, and the value, thus ensuring arrays are iterated similarly to hashes.
49 50 51 52 53 54 55 |
# File 'lib/rinda2/rinda.rb', line 49 def each # FIXME if Hash === @tuple @tuple.each { |k, v| yield(k, v) } else @tuple.each_with_index { |v, k| yield(k, v) } end end |
#fetch(k) ⇒ Object
Fetches item k
from the tuple.
41 42 43 |
# File 'lib/rinda2/rinda.rb', line 41 def fetch(k) @tuple.fetch(k) end |
#size ⇒ Object
The number of elements in the tuple.
27 28 29 |
# File 'lib/rinda2/rinda.rb', line 27 def size @tuple.size end |
#value ⇒ Object
Return the tuple itself
59 60 61 |
# File 'lib/rinda2/rinda.rb', line 59 def value @tuple end |