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
-
#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
5 |
# File 'lib/sequence/arraylike.rb', line 5 def data_class; Array end |
#index(pat, pos = 0) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/sequence/arraylike.rb', line 38 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
6 |
# File 'lib/sequence/arraylike.rb', line 6 def like; ArrayLike end |
#push(*arr) ⇒ Object
I ought to have #match and #matchback like in StringLike too
30 31 32 |
# File 'lib/sequence/arraylike.rb', line 30 def push(*arr) append arr end |
#rindex(pat, pos = -1) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/sequence/arraylike.rb', line 47 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
8 9 10 11 |
# File 'lib/sequence/arraylike.rb', line 8 def scan(pat) elem=nil more_data? and holding?{pat===(elem=read1)} and return [elem] end |
#scan_until(pat) ⇒ Object
13 14 15 16 |
# File 'lib/sequence/arraylike.rb', line 13 def scan_until pat i=index(pat,pos) or return read(i-pos)+scan(pat) end |
#scanback(pat) ⇒ Object
18 19 20 21 |
# File 'lib/sequence/arraylike.rb', line 18 def scanback pat elem=nil was_data? and holding?{pat===(elem=readback1)} and return [elem] end |
#scanback_until(pat) ⇒ Object
23 24 25 26 |
# File 'lib/sequence/arraylike.rb', line 23 def scanback_until pat i=rindex(pat,pos) or return readback(pos-i) end |
#unshift(*arr) ⇒ Object
34 35 36 |
# File 'lib/sequence/arraylike.rb', line 34 def unshift(*arr) prepend arr end |