module Sequence::ArrayLike

Public Instance Methods

data_class() click to toggle source
# File lib/sequence/arraylike.rb, line 9
def data_class; Array end
index(pat,pos=0) click to toggle source
# File lib/sequence/arraylike.rb, line 42
def index pat,pos=0
  pos=_normalize_pos(pos)
  begin
    pat===(slice pos) and return pos
    pos+=1
  end until pos>=size
  nil
end
like() click to toggle source
# File lib/sequence/arraylike.rb, line 10
def like; ArrayLike end
new_data() click to toggle source
Return an empty object used for returning a sequence of elements.
The only method required of this object is << (append to the sequence).

usually [] or “”

# File lib/sequence/arraylike.rb, line 8
def new_data; [] end
push(*arr) click to toggle source

I ought to have match and matchback like in StringLike too

# File lib/sequence/arraylike.rb, line 34
def push(*arr)
  append arr
end
rindex(pat,pos=-1) click to toggle source
# File lib/sequence/arraylike.rb, line 51
def rindex pat,pos=-1
  pos=_normalize_pos(pos)
  begin
    pat===(slice pos) and return pos
    pos-=1
  end until pos<0
  nil
end
scan(pat) click to toggle source
# File lib/sequence/arraylike.rb, line 12
def scan(pat)
    elem=nil
    more_data? and holding?{pat===(elem=read1)} and return [elem]
end
scan_until(pat) click to toggle source
# File lib/sequence/arraylike.rb, line 17
def scan_until pat
    i=index(pat,pos) or return
    read(i-pos)+scan(pat)
end
scanback(pat) click to toggle source
# File lib/sequence/arraylike.rb, line 22
def scanback pat
    elem=nil
    was_data? and holding?{pat===(elem=readback1)} and return [elem]
end
scanback_until(pat) click to toggle source
# File lib/sequence/arraylike.rb, line 27
def scanback_until pat
    i=rindex(pat,pos) or return
    readback(pos-i)
end
unshift(*arr) click to toggle source
# File lib/sequence/arraylike.rb, line 38
def unshift(*arr)
  prepend arr
end