Sha256: 8b04ea40b41a3e691700b877c48ba5b5aeda52b73310ef55f0e6db724bb96811
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
# frozen_string_literal: true # @api public # @author darthjee # # Extension to core class Object class Object # rubocop:disable Naming/PredicateName # @api public # Checks if an object is an instance of any of the given classes # # @param classes [Array<Class>] classes to be checked against object # # @example # object = [1, 2, 3] # # object.is_any?(Hash, Class) # returns false # object.is_any?(Hash, Array) # returns true # # @return [TrueClass,FalseClass] def is_any?(*classes) classes.any?(method(:is_a?)) end # rubocop:enable Naming/PredicateName # Maps the elements into a new value, returning only one # # The result to be returned is # the first mapping that is evaluated to true # # This method is equivalent to #map#find but # only calling the map block up to when a value # is found # # @yield (*args) mappig block # # @example Using an array of keys to remove remove elements of a hash # # service_map = { # a: nil, # b: false, # c: 'found me', # d: nil, # e: 'didnt find me' # } # # keys = %i[a b c d e] # # keys.map_and_find do |key| # # service_values.delete(key) # # end # returns 'found me' # # service_map # has lost only 3 keys returning # # { d: nil, e: 'didnt find me' } # # @return [::Object] def map_and_find mapped = nil find do |*args| mapped = yield(*args) end mapped || nil end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sinclair-2.1.1 | lib/sinclair/core_ext/object.rb |
sinclair-2.1.0 | lib/sinclair/core_ext/object.rb |