Class: JvmBytecode::Constants::Utf8
- Defined in:
- lib/jvm_bytecode/constants/utf8.rb
Class Method Summary collapse
Instance Method Summary collapse
- #additional_bytecode ⇒ Object
-
#initialize(str) ⇒ Utf8
constructor
A new instance of Utf8.
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods inherited from Constant
Constructor Details
#initialize(str) ⇒ Utf8
Returns a new instance of Utf8.
11 12 13 14 |
# File 'lib/jvm_bytecode/constants/utf8.rb', line 11 def initialize(str) raise "#{self.class} requires utf-8 string" unless str.encoding.to_s == 'UTF-8' @str = str end |
Class Method Details
.decode(io) ⇒ Object
6 7 8 9 |
# File 'lib/jvm_bytecode/constants/utf8.rb', line 6 def self.decode(io) str = io.read(io.read(2).unpack('S>').first).force_encoding('UTF-8') new(str) end |
Instance Method Details
#additional_bytecode ⇒ Object
20 21 22 23 |
# File 'lib/jvm_bytecode/constants/utf8.rb', line 20 def additional_bytecode s = @str.dup.force_encoding('ASCII-8BIT') [s.length].pack('S>') + s end |
#to_hash ⇒ Object
25 26 27 |
# File 'lib/jvm_bytecode/constants/utf8.rb', line 25 def to_hash { string: @str } end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/jvm_bytecode/constants/utf8.rb', line 16 def to_s @str end |