Class: JvmBytecode::Constants::NameAndType

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Constant

#bytecode, define, fetch

Constructor Details

#initialize(name_index, descriptor_index) ⇒ NameAndType

Returns a new instance of NameAndType.



13
14
15
16
# File 'lib/jvm_bytecode/constants/name_and_type.rb', line 13

def initialize(name_index, descriptor_index)
  @name_index = name_index
  @descriptor_index = descriptor_index
end

Instance Attribute Details

#descriptor_indexObject (readonly)

Returns the value of attribute descriptor_index.



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

def descriptor_index
  @descriptor_index
end

#name_indexObject (readonly)

Returns the value of attribute name_index.



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

def name_index
  @name_index
end

Class Method Details

.decode(io) ⇒ Object



8
9
10
11
# File 'lib/jvm_bytecode/constants/name_and_type.rb', line 8

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

Instance Method Details

#additional_bytecodeObject



18
19
20
# File 'lib/jvm_bytecode/constants/name_and_type.rb', line 18

def additional_bytecode
  [@name_index, @descriptor_index].pack('S>2')
end

#to_hashObject



22
23
24
25
26
27
# File 'lib/jvm_bytecode/constants/name_and_type.rb', line 22

def to_hash
  {
    name_index: @name_index,
    descriptor_index: @descriptor_index
  }
end