Class: Postscript::Model::Literals::HexLiteral
- Inherits:
-
Object
- Object
- Postscript::Model::Literals::HexLiteral
- Defined in:
- lib/postscript/model/literals/hex.rb
Overview
Hex-string literal: <DEADBEEF>.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #accept(visitor, ctx) ⇒ Object
-
#bytes ⇒ Object
Raw bytes encoded by the hex literal.
- #hash ⇒ Object
-
#initialize(value) ⇒ HexLiteral
constructor
A new instance of HexLiteral.
Constructor Details
#initialize(value) ⇒ HexLiteral
Returns a new instance of HexLiteral.
10 11 12 13 |
# File 'lib/postscript/model/literals/hex.rb', line 10 def initialize(value) @value = value.to_s freeze end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/postscript/model/literals/hex.rb', line 8 def value @value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
26 27 28 |
# File 'lib/postscript/model/literals/hex.rb', line 26 def ==(other) other.is_a?(HexLiteral) && other.value == value end |
#accept(visitor, ctx) ⇒ Object
22 23 24 |
# File 'lib/postscript/model/literals/hex.rb', line 22 def accept(visitor, ctx) visitor.visit_hex(self, ctx) end |
#bytes ⇒ Object
Raw bytes encoded by the hex literal.
16 17 18 19 20 |
# File 'lib/postscript/model/literals/hex.rb', line 16 def bytes hex = value.delete("^0-9a-fA-F") hex << "0" if hex.length.odd? hex.chars.each_slice(2).map { |pair| pair.join.to_i(16) }.pack("C*") end |
#hash ⇒ Object
31 32 33 |
# File 'lib/postscript/model/literals/hex.rb', line 31 def hash value.hash end |