Class: Sequence::OfArray

Inherits:
Indexed show all
Includes:
ArrayLike
Defined in:
lib/sequence/indexed.rb

Direct Known Subclasses

OfHash, OfObjectIvars, OfObjectMethods

Constant Summary

Constants inherited from Sequence

SubSequence, VERSION

Instance Attribute Summary

Attributes inherited from Indexed

#data, #pos

Attributes inherited from Sequence

#last_match, #maxmatchlen

Instance Method Summary collapse

Methods included from ArrayLike

#data_class, #like, #push, #scan, #scan_until, #scanback, #scanback_until, #unshift

Methods inherited from Indexed

_orig_new, #_pos=, #eof?, #initialize, #maxmatchlen, #maxmatchlen=, #modify

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, #_pos=, #all_data, #begin, #begin!, #check, #check_until, #checkback, #checkback_until, #close, #closed?, #delete, #each, #empty?, #end, #end!, #eof?, #exist?, #existback?, #first, #goto, #holding, #holding!, #holding?, #holding_position, #holding_position!, #holding_position?, #initialize, #insert, #last, #length, #match?, #matchback?, #modify, #more_data?, #move, #move!, #nearbegin, #nearend, #new, #notify_change, #on_change_notify, #original__new, #overwrite, #pop, #pos, #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

This class inherits a constructor from Sequence::Indexed

Instance Method Details

#append(arr) ⇒ Object



102
103
104
105
106
107
# File 'lib/sequence/indexed.rb', line 102

def append(arr)
  sz=size
  @data.push(*arr)
  notify_change(self,sz,0,arr.size)
  self
end

#index(pat, offset = 0) ⇒ Object

a better, string-like #index… with an offset parameter scalar matchers only



87
88
89
90
91
92
# File 'lib/sequence/indexed.rb', line 87

def index(pat,offset=0)
  pat=pat.dup
  class<<pat; alias == ===; end
  offset.zero? and return( @data.index pat)
  @data[offset..-1].index(pat)+offset
end

#new_dataObject



109
110
111
# File 'lib/sequence/indexed.rb', line 109

def new_data
  []
end

#rindex(pat, offset = size) ⇒ Object

a better, string-like #rindex… with an offset parameter scalar matchers only



96
97
98
99
100
# File 'lib/sequence/indexed.rb', line 96

def rindex(pat,offset=size)
  pat=pat.dup
  class<<pat; alias == ===; end
  (offset==size ? @data : @data[0...offset]).rindex pat
end