Sha256: ef24797d780f61434387248f6388ed2e0e6e61665abf29debb3ea062a8488db2

Contents?: true

Size: 673 Bytes

Versions: 3

Compression:

Stored size: 673 Bytes

Contents

module Api
  # Adds additional functionality to message object Api::Point2D
  module Point2DExtension
    # @private
    def hash
      [x, y].hash
    end

    def eql?(other)
      self.class == other.class && hash == other.hash
    end

    # Adds additional functionality to message class Api::Point2D
    module ClassMethods
      # Shorthand for creating an instance for [x, y]
      # @example
      #   Api::Point2D[2,4] # Where x is 2.0 and y is 4.0
      # @return [Api::Point2D]
      def [](x, y)
        Api::Point2D.new(x: x, y: y)
      end
    end
  end
end
Api::Point2D.include Api::Point2DExtension
Api::Point2D.extend Api::Point2DExtension::ClassMethods

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sc2ai-0.0.4 lib/sc2ai/protocol/extensions/point_2_d.rb
sc2ai-0.0.3 lib/sc2ai/protocol/extensions/point_2_d.rb
sc2ai-0.0.2 lib/sc2ai/protocol/extensions/point_2_d.rb