Class: JvmBytecode::Constants::Ref

Inherits:
Constant
  • Object
show all
Defined in:
lib/jvm_bytecode/constants/ref.rb

Direct Known Subclasses

MethodRef

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Constant

#bytecode, define, fetch

Constructor Details

#initialize(class_index, name_and_type_index) ⇒ Ref

Returns a new instance of Ref.



11
12
13
14
# File 'lib/jvm_bytecode/constants/ref.rb', line 11

def initialize(class_index, name_and_type_index)
  @class_index = class_index
  @name_and_type_index = name_and_type_index
end

Instance Attribute Details

#class_indexObject (readonly)

Returns the value of attribute class_index.



4
5
6
# File 'lib/jvm_bytecode/constants/ref.rb', line 4

def class_index
  @class_index
end

#name_and_type_indexObject (readonly)

Returns the value of attribute name_and_type_index.



4
5
6
# File 'lib/jvm_bytecode/constants/ref.rb', line 4

def name_and_type_index
  @name_and_type_index
end

Class Method Details

.decode(io) ⇒ Object



6
7
8
9
# File 'lib/jvm_bytecode/constants/ref.rb', line 6

def self.decode(io)
  indexes = io.read(4).unpack('S>2')
  new(*indexes)
end

Instance Method Details

#additional_bytecodeObject



16
17
18
# File 'lib/jvm_bytecode/constants/ref.rb', line 16

def additional_bytecode
  [@class_index, @name_and_type_index].pack('S>2')
end

#to_hashObject



20
21
22
23
24
25
# File 'lib/jvm_bytecode/constants/ref.rb', line 20

def to_hash
  {
    class_index: @class_index,
    name_and_type_index: @name_and_type_index
  }
end