Class: LightIO::RawProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/lightio/raw_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, methods: [], instance_methods: []) ⇒ RawProxy

Returns a new instance of RawProxy.



6
7
8
9
10
# File 'lib/lightio/raw_proxy.rb', line 6

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

Instance Method Details

#instance_send(instance, method, *args) ⇒ Object



18
19
20
21
22
# File 'lib/lightio/raw_proxy.rb', line 18

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

#send(method, *args) ⇒ Object



12
13
14
15
16
# File 'lib/lightio/raw_proxy.rb', line 12

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