Sha256: dc4a842f7fee1b148041703ff088a88a7fa7a1e8cb34bf38ceeae5ea462c3f90

Contents?: true

Size: 805 Bytes

Versions: 6

Compression:

Stored size: 805 Bytes

Contents

# helper for access raw ruby object methods
# use it to avoid monkey patch affect

module LightIO
  class RawProxy
    def initialize(klass, methods: [], instance_methods: [])
      @klass = klass
      @methods = methods.map {|method| [method.to_sym, klass.method(method)]}.to_h
      @instance_methods = instance_methods.map {|method| [method.to_sym, klass.instance_method(method)]}.to_h
    end

    def send(method, *args)
      method = method.to_sym
      return method_missing(method, *args) unless @methods.key?(method)
      @methods[method].call(*args)
    end

    def instance_send(instance, method, *args)
      method = method.to_sym
      return method_missing(method, *args) unless @instance_methods.key?(method)
      @instance_methods[method].bind(instance).call(*args)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lightio-0.4.4 lib/lightio/raw_proxy.rb
lightio-0.4.3 lib/lightio/raw_proxy.rb
lightio-0.4.2 lib/lightio/raw_proxy.rb
lightio-0.4.1 lib/lightio/raw_proxy.rb
lightio-0.4.0 lib/lightio/raw_proxy.rb
lightio-0.4.0.pre lib/lightio/raw_proxy.rb