Class: RubyLabs::BitLab::HexCode
Overview
HexCode
HexCodes are Code objects that are printed in hexadecimal. All of the attributes and methods of the Code class are applicable to HexCodes – the only differences are in to_s
, which generates the string of digits used to print a number, and in the method that compares objects (Codes can only be compared to other Codes, HexCodes to other HexCodes).
Instance Attribute Summary
Attributes inherited from Code
Instance Method Summary collapse
-
#<=>(x) ⇒ Object
Compare the numeric values of this object and HexCode object
x
. -
#initialize(x, length = log2(x+1).ceil) ⇒ HexCode
constructor
Create a new HexCode object for the number
x
. -
#inspect ⇒ Object
(also: #to_s)
Return a string with the hexadecimal digits of the value represented by this Code object.
Methods inherited from Code
#+, #<<, #[], #add_parity_bit, #chr, #even_parity?, #flip, #parity_bit
Constructor Details
Instance Method Details
#<=>(x) ⇒ Object
Compare the numeric values of this object and HexCode object x
.
753 754 755 |
# File 'lib/bitlab.rb', line 753 def <=>(x) return x.class == HexCode && @value <=> x.value end |
#inspect ⇒ Object Also known as: to_s
Return a string with the hexadecimal digits of the value represented by this Code object.
759 760 761 762 763 764 765 |
# File 'lib/bitlab.rb', line 759 def inspect if @length == 0 return "" else return sprintf "%0#{@length/4}X", @value end end |