A tuple is the elementary object in Rinda programming. Tuples may be matched against templates if the tuple and the template are the same size.
Accessor method for elements of the tuple.
# File lib/rinda/rinda.rb, line 68 def [](k) @tuple[k] end
Iterate through the tuple, yielding the index or key, and the value, thus ensuring arrays are iterated similarly to hashes.
# File lib/rinda/rinda.rb, line 83 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
Fetches item k
from the tuple.
# File lib/rinda/rinda.rb, line 75 def fetch(k) @tuple.fetch(k) end
The number of elements in the tuple.
# File lib/rinda/rinda.rb, line 61 def size @tuple.size end
Return the tuple itself
# File lib/rinda/rinda.rb, line 93 def value @tuple end
# File lib/rinda/rinda.rb, line 99 def hash?(ary_or_hash) ary_or_hash.respond_to?(:keys) end
Munges ary
into a valid Tuple.
# File lib/rinda/rinda.rb, line 106 def init_with_ary(ary) @tuple = Array.new(ary.size) @tuple.size.times do |i| @tuple[i] = ary[i] end end
Ensures hash
is a valid Tuple.
# File lib/rinda/rinda.rb, line 116 def init_with_hash(hash) @tuple = Hash.new hash.each do |k, v| raise InvalidHashTupleKey unless String === k @tuple[k] = v end end
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.