Sha256: 406a793f87d9727ee717136b408d601aafd1c702cfc3adebbf3c70e03fa5e4ae

Contents?: true

Size: 873 Bytes

Versions: 3

Compression:

Stored size: 873 Bytes

Contents

# encoding: utf-8

module Rubymisc
  module Object
    def in?(collection)
      collection.respond_to?(:include?) ? collection.include?(self) : false
    end

    def not
      _not_functor = ->(op, *a, &b) { !self.__send__(op, *a, &b) }

      _not_functor.singleton_class.module_eval <<-CODE
        def method_missing(method, *args, &block)
          call method, *args, &block
        end
      CODE

      _not_functor
    end

    def and_try
      _and_try_functor = BasicObject.new
      (class << _and_try_functor; self; end).module_eval do
        attr_accessor :delegate_to

        def method_missing(method, *args, &block)
          delegate_to ? delegate_to.__send__(method, *args, &block) : delegate_to
        end
      end
      _and_try_functor.delegate_to = self
      _and_try_functor
    end
  end
end

::Object.module_eval 'include Rubymisc::Object'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubymisc-0.2.0 lib/rubymisc/ext/object.rb
rubymisc-0.1.0 lib/rubymisc/ext/object.rb
rubymisc-0.0.4 lib/rubymisc/ext/object.rb