Class: BitStream::ArrayProxy
- Inherits:
-
Object
- Object
- BitStream::ArrayProxy
- Includes:
- RandomAccessible
- Defined in:
- lib/bitstream.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #add_field(field) ⇒ Object
- #get_field(pos) ⇒ Object
-
#initialize(instance) ⇒ ArrayProxy
constructor
A new instance of ArrayProxy.
- #read_access(pos) ⇒ Object
- #shrink(n) ⇒ Object
- #write_access(pos, val) ⇒ Object
Constructor Details
#initialize(instance) ⇒ ArrayProxy
Returns a new instance of ArrayProxy.
36 37 38 39 40 41 42 |
# File 'lib/bitstream.rb', line 36 def initialize(instance) @fields = [] @values = [] @updated = [] @instance = instance @size = 0 end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
79 80 81 |
# File 'lib/bitstream.rb', line 79 def size @size end |
Instance Method Details
#add_field(field) ⇒ Object
44 45 46 47 |
# File 'lib/bitstream.rb', line 44 def add_field(field) @fields << field @size += 1 end |
#get_field(pos) ⇒ Object
49 50 51 |
# File 'lib/bitstream.rb', line 49 def get_field(pos) @fields[pos] end |
#read_access(pos) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/bitstream.rb', line 53 def read_access(pos) unless @updated[pos] field = @fields[pos] @values[pos] = field.value @fields[pos] = nil @updated[pos] = true end return @values[pos] end |
#shrink(n) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/bitstream.rb', line 69 def shrink(n) @fields.pop(n) @size -= n dif = @values.size - @size if dif > 0 @values.pop(dif) @updated.pop(dif) end end |
#write_access(pos, val) ⇒ Object
63 64 65 66 67 |
# File 'lib/bitstream.rb', line 63 def write_access(pos, val) @fields[pos] = nil @values[pos] = val @updated[pos] = true end |