Sha256: eb06092d75915f56ea415859bf10200d83e1bcb13e575ac69c4161cb99eaf48f

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module Python
  module Pickle
    module Instructions
      #
      # A mixin which adds a value to an instruction class.
      #
      module HasValue
        # The value associated with the instruction.
        #
        # @return [Object]
        attr_reader :value

        #
        # Initializes the instruction.
        #
        # @param [Symbol] opcode
        #
        # @param [Object] value
        #
        def initialize(opcode,value)
          super(opcode)

          @value = value
        end

        #
        # Compares the instruction to another instruction.
        #
        # @param [Instruction] other
        #   The other instruction to compare against.
        #
        # @return [Boolean]
        #   Indicates whether the other instruction matches this one.
        #
        def ==(other)
          super(other) && other.kind_of?(HasValue) && (@value == other.value)
        end

        #
        # Converts the instruction to a String.
        #
        # @return [String]
        #
        def to_s
          "#{super} #{@value.inspect}"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
python-pickle-0.2.0 lib/python/pickle/instructions/has_value.rb
python-pickle-0.1.1 lib/python/pickle/instructions/has_value.rb
python-pickle-0.1.0 lib/python/pickle/instructions/has_value.rb