Sha256: f48baefb6079966d21f9dadcc2dd4242533de68320dc8079b96d712bc0ae0f00

Contents?: true

Size: 596 Bytes

Versions: 6

Compression:

Stored size: 596 Bytes

Contents

# frozen_string_literal: true

module Refinements
  # Provides additional enhancements to the Object class.
  module Object
    refine ::Object do
      def in? other
        case other
          when Range then other.cover? self
          when ::Array, Enumerable, ::Hash, Set, ::String then other.include? self
          else fail NoMethodError, "`#{self.class}#include?` must be implemented."
        end
      end

      def to_proc
        return method(:call).to_proc if respond_to? :call

        fail NoMethodError, "`#{self.class}#call` must be implemented."
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
refinements-12.11.0 lib/refinements/object.rb
refinements-12.10.0 lib/refinements/object.rb
refinements-12.9.0 lib/refinements/object.rb
refinements-12.8.0 lib/refinements/object.rb
refinements-12.7.1 lib/refinements/object.rb
refinements-12.7.0 lib/refinements/object.rb