Class: Sequence::OfObjectIvars

Inherits:
OfArray show all
Defined in:
lib/sequence/ofobjectivars.rb

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 inherited from OfArray

#append, #index, #new_data, #rindex

Methods included from ArrayLike

#data_class, #index, #like, #new_data, #push, #rindex, #scan, #scan_until, #scanback, #scanback_until, #unshift

Methods inherited from Indexed

_orig_new, #_pos=, #eof?, #maxmatchlen, #maxmatchlen=, new, #new_data

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, #append, #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?, #insert, #last, #length, #match?, #matchback?, #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

#initialize(obj, exceptions = [], modifiable = false) ⇒ OfObjectIvars

Returns a new instance of OfObjectIvars.



9
10
11
12
13
14
# File 'lib/sequence/ofobjectivars.rb', line 9

def initialize(obj,exceptions=[],modifiable=false)
  @obj=obj
  ivars=obj.instance_variables - exceptions
  @data=ivars.inject([]){|l,name| l.push name,obj.instance_variable_get(name)}
  @data.freeze unless modifiable
end

Instance Method Details

#modify(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sequence/ofobjectivars.rb', line 16

def modify(*args)
  repldata=args.pop
  start,len,only1=_parse_slice_args(*args)
  len==1 or raise "scalar modifications to objects only!"
  assert start.%(2).nonzero? #not a name 
  
  @obj.instance_variable_set(@data[start-1],repldata.first)
  @data[start]=repldata.first 
  repldata
  
end