class Sequence::OfHash
Public Class Methods
new(hash,exceptions=[],include_default=false,modifiable=false)
click to toggle source
# File lib/sequence/ofhash.rb, line 8 def initialize(hash,exceptions=[],include_default=false,modifiable=false) @hash=hash hash=hash.dup exceptions.each{|exc| hash.delete exc } @data=hash.inject([]){|l,pair| l+pair} @data<<hash.default if include_default @data.freeze unless modifiable end
Public Instance Methods
modify(*args)
click to toggle source
# File lib/sequence/ofhash.rb, line 17 def modify(*args) repldata=args.pop start,len,only1=_parse_slice_args(*args) len==1 or raise "scalar modifications to hashes only!" if @data.size.%(2).nonzero? and @data.size.-(1)==start @hash.default=repldata.first elsif start.%(2).zero? #key @hash[repldata.first]=@hash.delete @data[start] else #value @hash[@data[start-1]]=repldata.first end @data[first]=repldata.first repldata end