Class: PipeOperator::Proxy
- Inherits:
-
Module
- Object
- Module
- PipeOperator::Proxy
- Defined in:
- lib/pipe_operator/proxy.rb
Instance Method Summary collapse
- #define(method) ⇒ Object
- #definitions ⇒ Object
-
#initialize(object, singleton) ⇒ Proxy
constructor
A new instance of Proxy.
- #inspect ⇒ Object
- #prepended ⇒ Object
- #undefine(method) ⇒ Object
Constructor Details
#initialize(object, singleton) ⇒ Proxy
Returns a new instance of Proxy.
3 4 5 6 7 |
# File 'lib/pipe_operator/proxy.rb', line 3 def initialize(object, singleton) @object = object if singleton.singleton_class? @singleton = singleton super() end |
Instance Method Details
#define(method) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pipe_operator/proxy.rb', line 9 def define(method) if ::Proc == @object && method == :new return method elsif ::Symbol == @singleton && method == :to_proc return method elsif ::Module === @object namespace = @object.name.to_s.split("::").first return method if namespace == "PipeOperator" end define_method(method) do |*args, &block| if Pipe.open Pipe.new(self).__send__(method, *args, &block) else super(*args, &block) end end end |
#definitions ⇒ Object
28 29 30 |
# File 'lib/pipe_operator/proxy.rb', line 28 def definitions instance_methods(false).sort end |
#inspect ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pipe_operator/proxy.rb', line 32 def inspect inspect = if @singleton.singleton_class? ::PipeOperator.inspect(@object) else "#<#{@singleton.name}>" end "#<#{self.class.name}:#{inspect}>" end |
#prepended ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/pipe_operator/proxy.rb', line 43 def prepended(*) if is_a?(Proxy) methods = @singleton.instance_methods(false) methods.each { |method| define(method) } end super end |
#undefine(method) ⇒ Object
52 53 54 55 56 |
# File 'lib/pipe_operator/proxy.rb', line 52 def undefine(method) remove_method(method) rescue ::NameError # ignore method end |