Sha256: ae6190f3d4821cfb7a9fb831eaae53883259ed9aa15ddb465795d2c72a1de14b

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module Celluloid::Proxy
  # Looks up the actual class of instance, even if instance is a proxy.
  def self.class_of(instance)
    (class << instance; self; end).superclass
  end
end

# Base class of Celluloid proxies
class Celluloid::Proxy::Abstract < BasicObject
  # Needed for storing proxies in data structures
  needed = [:object_id, :__id__, :hash, :eql?, :private_methods] - instance_methods
  if needed.any?
    include ::Kernel.dup.module_eval {
      undef_method(*(instance_methods - needed))
      self
    }
    # rubinius bug?  These methods disappear when we include hacked kernel
    define_method :==, ::BasicObject.instance_method(:==) unless instance_methods.include?(:==)
    alias_method(:equal?, :==) unless instance_methods.include?(:equal?)
  end
  
  def __class__
    @class ||= ::Celluloid::Proxy.class_of(self)
  end
end

class Celluloid::Proxy::AbstractCall < Celluloid::Proxy::Abstract
  attr_reader :mailbox
  
  def initialize(mailbox, klass)
    @mailbox = mailbox
    @klass = klass
  end
  
  def eql?(other)
    self.__class__.eql?(::Celluloid::Proxy.class_of(other)) and @mailbox.eql?(other.mailbox)
  end

  def hash
    @mailbox.hash
  end
  
  def __klass__
    @klass
  end
  
  def inspect
    "#<#{self.__class__}(#{@klass})>"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
celluloid-0.17.4 lib/celluloid/proxy/abstract.rb
celluloid-0.18.0.pre lib/celluloid/proxy/abstract.rb
celluloid-0.17.3 lib/celluloid/proxy/abstract.rb