Module: Sequence::ArrayLike
- Included in:
- OfArray, SingleItem
- Defined in:
- lib/sequence/arraylike.rb
Instance Method Summary collapse
- #data_class ⇒ Object
- #index(pat, pos = 0) ⇒ Object
- #like ⇒ Object
-
#new_data ⇒ Object
Return an empty object used for returning a sequence of elements.
-
#push(*arr) ⇒ Object
I ought to have #match and #matchback like in StringLike too.
- #rindex(pat, pos = -1) ⇒ Object
- #scan(pat) ⇒ Object
- #scan_until(pat) ⇒ Object
- #scanback(pat) ⇒ Object
- #scanback_until(pat) ⇒ Object
- #unshift(*arr) ⇒ Object
Instance Method Details
#data_class ⇒ Object
9 |
# File 'lib/sequence/arraylike.rb', line 9 def data_class; Array end |
#index(pat, pos = 0) ⇒ Object
42 43 44 45 46 47 48 49 |
# 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 ⇒ Object
10 |
# File 'lib/sequence/arraylike.rb', line 10 def like; ArrayLike end |
#new_data ⇒ Object
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 “”
8 |
# File 'lib/sequence/arraylike.rb', line 8 def new_data; [] end |
#push(*arr) ⇒ Object
I ought to have #match and #matchback like in StringLike too
34 35 36 |
# File 'lib/sequence/arraylike.rb', line 34 def push(*arr) append arr end |
#rindex(pat, pos = -1) ⇒ Object
51 52 53 54 55 56 57 58 |
# 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) ⇒ Object
12 13 14 15 |
# 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) ⇒ Object
17 18 19 20 |
# 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) ⇒ Object
22 23 24 25 |
# 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) ⇒ Object
27 28 29 30 |
# File 'lib/sequence/arraylike.rb', line 27 def scanback_until pat i=rindex(pat,pos) or return readback(pos-i) end |
#unshift(*arr) ⇒ Object
38 39 40 |
# File 'lib/sequence/arraylike.rb', line 38 def unshift(*arr) prepend arr end |