module Pipeful::PipableObject

Public Instance Methods

pipe_arity() click to toggle source
# File lib/pipeful.rb, line 83
def pipe_arity
  case pipe_type
  when :instance_function
    method = instance_method(:call)
  when :function_object, :class_function
    if is_a?(Proc)
      method = self
    else
      method = method(:call)
    end
  when :object_class
    method = instance_method(:initialize)
  when :object
    return 0..0
  end
  method.extend(ArityRange).arity_range
end
pipe_target() click to toggle source
# File lib/pipeful.rb, line 70
def pipe_target
  case pipe_type
  when :instance_function
    ->(*args, &block) { new.call(*args, &block) }
  when :function_object, :class_function
    ->(*args, &block) { call(*args, &block) }
  when :object_class
    ->(*args, &block) { new(*args, &block) }
  when :object
    nil
  end
end
pipe_type() click to toggle source
# File lib/pipeful.rb, line 101
def pipe_type
  if methods.include?(:instance_methods)
    if methods.include?(:call)
      :class_function
    elsif instance_methods.include?(:call)
      :instance_function
    else
      :object_class
    end
  elsif methods.include?(:call)
    :function_object
  else
    :object
  end
end