Class: Ick::Split

Inherits:
Wrap show all
Defined in:
lib/ick/tee.rb

Direct Known Subclasses

Fork, Tee

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Wrap

#invoke_wrapped, #wrap

Methods inherited from Base

#evaluate, evaluates_in_calling_environment, evaluates_in_value_environment, #returns, returns_result, returns_value, underscore

Class Method Details

.belongs_to(clazz) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ick/tee.rb', line 13

def self.belongs_to clazz
  method_name = self.underscore(self.name.split('::')[-1])
  unless clazz.method_defined?(method_name)
    clazz.class_eval " 
      def #{method_name}(*values,&proc)
        values = [self] if values.empty?
        if block_given?
          #{self.name}.instance.invoke(*values, &proc)
        else
          Invoker.new(values, #{self.name})
        end
      end"
  end
end

Instance Method Details

#invoke(*values, &proc) ⇒ Object



5
6
7
# File 'lib/ick/tee.rb', line 5

def invoke(*values, &proc)
  invoke_wrapped(values, ArrayWrapper, nil, &proc)
end

#unwrap(wrapped, wrapper_class) ⇒ Object



9
10
11
# File 'lib/ick/tee.rb', line 9

def unwrap(wrapped, wrapper_class)
  wrapped.respond_to?(:__value__) ? wrapped.__value__.first : wrapped
end