Sha256: 7f878bcd2ed02c911ec9ee3699fae632bbdee548da392894ed6a524f67d2436f

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'python/pickle/instruction'
require 'python/pickle/instructions/has_value'

module Python
  module Pickle
    module Instructions
      class Global < Instruction

        # The global object namespace.
        #
        # @return [String]
        attr_reader :namespace

        # The global object name.
        #
        # @return [String]
        attr_reader :name

        #
        # Initializes the `GLOBAL` instruction.
        #
        # @param [String] namespace
        #   The namespace name for the global object.
        #
        # @param [String] name
        #   The name of the global object.
        #
        def initialize(namespace,name)
          super(:GLOBAL)

          @namespace = namespace
          @name      = name
        end

        #
        # Compares the `GLOBAL` 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) && \
            (@namespace == other.namespace) && \
            (@name == other.name)
        end

        #
        # Converts the `GLOBAL` instructions to a String.
        #
        # @return [String]
        #
        def to_s
          "#{super} #{@namespace}.#{@name}"
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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