Class: Brainfucktt::Byte
- Inherits:
-
Object
- Object
- Brainfucktt::Byte
- Includes:
- ConversionHelpers, Comparable
- Defined in:
- lib/brainfucktt/byte.rb
Overview
A Byte.
Instance Method Summary collapse
-
#+(value) ⇒ Integer
Add to this Byte instance’s value.
-
#-(value) ⇒ Integer
Subtract from this Byte instance’s value.
-
#<=>(other) ⇒ nil, Integer
Compare with another Byte, Integer, String, etc..
-
#==(other) ⇒ true, false
Check to see if the given object instance is the same instance as self.
-
#empty? ⇒ true, false
Check this Byte instance is empty.
-
#eql?(other) ⇒ true, false
(also: #equal?)
Check to see if the given object instance as an Integer is the same as the value of this Byte instance.
-
#initialize(value = 0) ⇒ Byte
constructor
Set the value of the Byte instance at the given offset.
-
#inspect ⇒ String
Return the Byte as a binary string.
-
#to_ascii ⇒ String
(also: #to_s)
Return the Byte as an ASCII character.
-
#to_binary ⇒ String
Return the Byte as a binary string.
-
#to_hex ⇒ String
Return the Byte as a hexadecimal string.
-
#to_i ⇒ Integer
Return the Byte as an Integer.
Constructor Details
#initialize(value = 0) ⇒ Byte
Set the value of the Byte instance at the given offset.
14 15 16 |
# File 'lib/brainfucktt/byte.rb', line 14 def initialize(value=0) @value = convert_to_integer(value) end |
Instance Method Details
#+(value) ⇒ Integer
Add to this Byte instance’s value.
23 24 25 |
# File 'lib/brainfucktt/byte.rb', line 23 def +(value) @value += convert_to_integer(value) end |
#-(value) ⇒ Integer
Subtract from this Byte instance’s value.
32 33 34 |
# File 'lib/brainfucktt/byte.rb', line 32 def -(value) @value -= convert_to_integer(value) end |
#<=>(other) ⇒ nil, Integer
Compare with another Byte, Integer, String, etc..
39 40 41 |
# File 'lib/brainfucktt/byte.rb', line 39 def <=>(other) @value <=> convert_to_integer(other) end |
#==(other) ⇒ true, false
Check to see if the given object instance is the same instance as self.
46 47 48 |
# File 'lib/brainfucktt/byte.rb', line 46 def ==(other) self.object_id == other.object_id end |
#empty? ⇒ true, false
Check this Byte instance is empty.
62 63 64 |
# File 'lib/brainfucktt/byte.rb', line 62 def empty? @value == 0 end |
#eql?(other) ⇒ true, false Also known as: equal?
Check to see if the given object instance as an Integer is the same as the value of this Byte instance.
54 55 56 |
# File 'lib/brainfucktt/byte.rb', line 54 def eql?(other) @value == convert_to_integer(other) end |
#inspect ⇒ String
Return the Byte as a binary string.
98 99 100 |
# File 'lib/brainfucktt/byte.rb', line 98 def inspect "#<#{self.class}:#{object_id.to_s(16)} integer=#{to_i.inspect} hex=#{to_hex.inspect} ascii=#{to_ascii.inspect} binary=#{to_binary.inspect} >" end |
#to_ascii ⇒ String Also known as: to_s
Return the Byte as an ASCII character.
83 84 85 |
# File 'lib/brainfucktt/byte.rb', line 83 def to_ascii @value.chr end |
#to_binary ⇒ String
Return the Byte as a binary string.
76 77 78 |
# File 'lib/brainfucktt/byte.rb', line 76 def to_binary "%08b" % @value end |
#to_hex ⇒ String
Return the Byte as a hexadecimal string.
91 92 93 |
# File 'lib/brainfucktt/byte.rb', line 91 def to_hex '%02x' % @value end |
#to_i ⇒ Integer
Return the Byte as an Integer
69 70 71 |
# File 'lib/brainfucktt/byte.rb', line 69 def to_i @value end |