class Pione::Lang::KeyedSequence
KeyedSequence
is a sequence that have key and value pairs.
Public Instance Methods
concat(other)
click to toggle source
Concatenate the sequence and another one.
@param other [Sequence]
other sequence
@return [Sequence]
a new sequence that have members of self and other
# File lib/pione/lang/keyed-sequence.rb, line 16 def concat(other) set(pieces: pieces.merge(other.pieces)) end
Also aliased as: +
each() { |set(pieces: {key => val})| ... }
click to toggle source
Iterate each elements.
# File lib/pione/lang/keyed-sequence.rb, line 38 def each if block_given? pieces.each {|key, val| yield set(pieces: {key => val})} else Enumerator.new(self, :each) end end
element_type(env)
click to toggle source
# File lib/pione/lang/keyed-sequence.rb, line 50 def element_type(env) pieces.values.first.pione_type(env) end
eval(env)
click to toggle source
# File lib/pione/lang/keyed-sequence.rb, line 54 def eval(env) _pieces = pieces.inject({}) do |_pieces, (key, val)| _pieces.update({key => val.map{|v| v.eval(env)}}) end set(pieces: _pieces) end
get(key)
click to toggle source
Get the element by the key.
# File lib/pione/lang/keyed-sequence.rb, line 22 def get(key) pieces[key] || (raise IndexError.new(key)) end
index_type(env)
click to toggle source
# File lib/pione/lang/keyed-sequence.rb, line 46 def index_type(env) pieces.keys.first.pione_type(env) end
inspect()
click to toggle source
# File lib/pione/lang/keyed-sequence.rb, line 65 def inspect name = "KeyedSequence" content = pieces.map {|key, val| "%s:(%s)" % [key.pieces.first.value, val.textize]}.join(",") "#<%s [%s]>" % [name, content] end
put(key, val)
click to toggle source
Put the element to the sequecence.
# File lib/pione/lang/keyed-sequence.rb, line 27 def put(key, val) raise ArgumentError.new(key) unless key.kind_of?(Sequence) raise ArgumentError.new(val) unless val.kind_of?(Sequence) begin set(pieces: pieces.merge({key => get(key) + val})) rescue IndexError set(pieces: pieces.merge({key => val})) end end
textize()
click to toggle source
# File lib/pione/lang/keyed-sequence.rb, line 61 def textize inspect end