Module: Python::Pickle::Instructions::HasLengthAndValue

Included in:
BinBytes, BinBytes8, BinString, BinUnicode, BinUnicode8, ByteArray8, Long1, Long4, ShortBinBytes, ShortBinString, ShortBinUnicode
Defined in:
lib/python/pickle/instructions/has_length_and_value.rb

Overview

A mixin which adds a length and a value to an instruction class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lengthInteger (readonly)

The length of the value associated with the instruction.

Returns:

  • (Integer)


11
12
13
# File 'lib/python/pickle/instructions/has_length_and_value.rb', line 11

def length
  @length
end

#valueObject (readonly)

The value associated with the instruction.

Returns:

  • (Object)


16
17
18
# File 'lib/python/pickle/instructions/has_length_and_value.rb', line 16

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean

Compares the instruction to another instruction.

Parameters:

  • other (Instruction)

    The other instruction to compare against.

Returns:

  • (Boolean)

    Indicates whether the other instruction matches this one.



41
42
43
44
45
# File 'lib/python/pickle/instructions/has_length_and_value.rb', line 41

def ==(other)
  super(other) &&
    other.kind_of?(HasLengthAndValue) &&
    (@length == other.length && @value == other.value)
end

#initialize(opcode, length, value) ⇒ Object

Initializes the instruction.

Parameters:

  • opcode (Symbol)
  • value (Object)


25
26
27
28
29
30
# File 'lib/python/pickle/instructions/has_length_and_value.rb', line 25

def initialize(opcode,length,value)
  super(opcode)

  @value  = value
  @length = length
end

#to_sString

Converts the instruction to a String.

Returns:



52
53
54
# File 'lib/python/pickle/instructions/has_length_and_value.rb', line 52

def to_s
  "#{super} #{@length.inspect} #{@value.inspect}"
end