Class: Sequence::Indexed
- Defined in:
- lib/sequence/indexed.rb
Overview
This class makes a seq over an Array or String.
Constant Summary
Constants inherited from Sequence
Instance Attribute Summary collapse
- #data ⇒ Object readonly
- #pos ⇒ Object readonly
Attributes inherited from Sequence
Class Method Summary collapse
Instance Method Summary collapse
- #_pos=(x) ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(data, pos = 0) ⇒ Indexed
constructor
A new instance of Indexed.
- #maxmatchlen(backwards) ⇒ Object
-
#maxmatchlen=(x) ⇒ Object
can’t change maxmatchlen (maybe someday?).
- #modify(*args) ⇒ Object (also: #[]=)
-
#new_data ⇒ Object
:stopdoc:.
Methods inherited from UseData
#read, #readahead, #readback, #readbehind, #size
Methods inherited from Sequence
#+, #-, #<<, [], #[], #_adjust_pos_on_change, #_default_maxmatchlen, #_delete_position, #_normalize_pos, #_parse_slice_args, #all_data, #append, #begin, #begin!, #check, #check_until, #checkback, #checkback_until, #close, #closed?, #delete, #each, #empty?, #end, #end!, #exist?, #existback?, #first, #goto, #holding, #holding!, #holding?, #holding_position, #holding_position!, #holding_position?, #insert, #last, #length, #match?, #matchback?, #more_data?, #move, #move!, #nearbegin, #nearend, #new, #notify_change, #on_change_notify, #original__new, #overwrite, #pop, #pos=, #pos?, #position, #position=, #position?, #pred, #prepend, #prop, #read, #read!, #read1, #readahead, #readahead1, #readback, #readback1, #readbehind, #readbehind1, #rest_size, #reversed, #shift, #size, #skip, #skip_literal, #skip_until, #skip_until_literal, #skipback, #skipback_until, #slice, #slice!, #slice1, #slice1!, #subseq, #succ, #to_sequence, #was_data?, #write, #writeahead, #writeback, #writebehind
Constructor Details
#initialize(data, pos = 0) ⇒ Indexed
Returns a new instance of Indexed.
25 26 27 28 |
# File 'lib/sequence/indexed.rb', line 25 def initialize(data,pos=0) @data = data @pos = pos end |
Instance Attribute Details
#data ⇒ Object (readonly)
protected
def _delete1after?
@data.slice!(@pos)
end
def _delete1before?
@pos==0 ? nil : @data.slice!(@pos-=1)
end
def _insert1before(v)
@data[@pos,0] = (new_data << v)
@pos += 1
true
end
def _insert1after(v)
@data[@pos,0] = (new_data << v)
true
end
public
54 55 56 |
# File 'lib/sequence/indexed.rb', line 54 def data @data end |
#pos ⇒ Object (readonly)
protected
def _delete1after?
@data.slice!(@pos)
end
def _delete1before?
@pos==0 ? nil : @data.slice!(@pos-=1)
end
def _insert1before(v)
@data[@pos,0] = (new_data << v)
@pos += 1
true
end
def _insert1after(v)
@data[@pos,0] = (new_data << v)
true
end
public
54 55 56 |
# File 'lib/sequence/indexed.rb', line 54 def pos @pos end |
Class Method Details
._orig_new ⇒ Object
16 |
# File 'lib/sequence/indexed.rb', line 16 alias _orig_new new |
.new(data, p = 0) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/sequence/indexed.rb', line 17 def new(data,p=0) if data.respond_to? :to_sequence data.to_sequence else _orig_new(data,p) end end |
Instance Method Details
#_pos=(x) ⇒ Object
55 |
# File 'lib/sequence/indexed.rb', line 55 def _pos= x; @pos=x end |
#eof? ⇒ Boolean
57 |
# File 'lib/sequence/indexed.rb', line 57 def eof?; @pos >= size end |
#maxmatchlen(backwards) ⇒ Object
61 |
# File 'lib/sequence/indexed.rb', line 61 def maxmatchlen(backwards) size end |
#maxmatchlen=(x) ⇒ Object
can’t change maxmatchlen (maybe someday?)
64 |
# File 'lib/sequence/indexed.rb', line 64 def maxmatchlen= x; end |
#modify(*args) ⇒ Object Also known as: []=
66 67 68 69 70 71 72 73 |
# File 'lib/sequence/indexed.rb', line 66 def modify(*args) newsize=args.last.size first,len,only1=_parse_slice_args( *args[0...-1]) @data.[]=(*args) @pos=_adjust_pos_on_change(@pos, first,len,newsize) notify_change(self,first,len,newsize) return args.last end |
#new_data ⇒ Object
:stopdoc:
30 31 32 |
# File 'lib/sequence/indexed.rb', line 30 def new_data @data.class.new end |