Class: Brainfucktt::Data
- Inherits:
-
Object
- Object
- Brainfucktt::Data
- Includes:
- ConversionHelpers
- Defined in:
- lib/brainfucktt/data.rb
Overview
An Array of Byte instances.
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Instance Method Summary collapse
-
#[](offset) ⇒ Byte
Retrieve the Byte instance at the given offset.
-
#[]=(offset, value) ⇒ Byte
Set the value of the Byte instance at the given offset.
-
#expand_to(offset) ⇒ Byte
Fill from the end of the Data collection to the given offset with empty Byte instances, if Data collection is less than the given offset.
-
#initialize ⇒ Data
constructor
A new instance of Data.
Constructor Details
#initialize ⇒ Data
Returns a new instance of Data.
12 13 14 |
# File 'lib/brainfucktt/data.rb', line 12 def initialize @bytes = [] end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
10 11 12 |
# File 'lib/brainfucktt/data.rb', line 10 def bytes @bytes end |
Instance Method Details
#[](offset) ⇒ Byte
Retrieve the Byte instance at the given offset.
21 22 23 24 25 26 |
# File 'lib/brainfucktt/data.rb', line 21 def [](offset) offset = convert_to_integer(offset) self[offset] = 0 if @bytes[offset].nil? @bytes[offset] end |
#[]=(offset, value) ⇒ Byte
Set the value of the Byte instance at the given offset.
35 36 37 38 39 |
# File 'lib/brainfucktt/data.rb', line 35 def []=(offset, value) (offset) @bytes[offset] = convert_to_byte(value) end |
#expand_to(offset) ⇒ Byte
Fill from the end of the Data collection to the given offset with empty Byte instances, if Data collection is less than the given offset.
47 48 49 50 51 52 |
# File 'lib/brainfucktt/data.rb', line 47 def (offset) offset = convert_to_integer(offset) (@bytes.length..offset).each { @bytes << Byte.new } if @bytes.at(offset).nil? @bytes[offset] end |