Sha256: 01c20c1706afbe052fd6c0d09c4a90118fcb02b0a8f063a32488e04e3b873e3c

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require "fancy_to_proc/version"
require "rubocop/cop/fancy_to_proc/space_around_most_operators"

module FancyToProc
end

class Symbol
  def ~
    method(self).to_proc
  end unless method_defined?(:~)

  def |(other)
    proc { |*args| args.shift.__send__(self, other) }
  end unless method_defined?(:|)

  def &(other)
    proc { |*args| other.to_proc.call to_proc.call(*args) }
  end unless method_defined?(:&)

  def call(*defaults)
    proc { |*args| args.shift.__send__(self, *defaults) }
  end unless method_defined?(:call)

  def respond_to?(method, include_private = false)
    super unless method == :call
  end
end

class Proc
  def |(other)
    curry(2)[other]
  end unless method_defined?(:|)

  def &(other)
    proc { |*args| other.to_proc.call call(*args) }
  end unless method_defined?(:&)
end

class Method
  def |(other)
    curry(2)[other]
  end unless method_defined?(:|)

  def &(other)
    proc { |*args| other.to_proc.call call(*args) }
  end unless method_defined?(:&)
end

class Array
  def to_proc
    proc { |args| args[*self] }
  end unless method_defined?(:to_proc)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fancy_to_proc-0.5.0 lib/fancy_to_proc.rb
fancy_to_proc-0.4.0 lib/fancy_to_proc.rb