module Rubymisc::Object

Public Instance Methods

and_try() click to toggle source
# File lib/rubymisc/ext/object.rb, line 21
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
in?(collection) click to toggle source
# File lib/rubymisc/ext/object.rb, line 5
def in?(collection)
  collection.respond_to?(:include?) ? collection.include?(self) : false
end
method_missing(method, *args, &block) click to toggle source
# File lib/rubymisc/ext/object.rb, line 26
def method_missing(method, *args, &block)
  delegate_to ? delegate_to.__send__(method, *args, &block) : delegate_to
end
not() click to toggle source
# File lib/rubymisc/ext/object.rb, line 9
    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