Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/sinclair/core_ext/object.rb
Overview
Extension to core class Object
Instance Method Summary collapse
-
#is_any?(*classes) ⇒ TrueClass, FalseClass
Checks if an object is an instance of any of the given classes.
-
#map_and_find {|*args| ... } ⇒ ::Object
Maps the elements into a new value, returning only one.
Instance Method Details
#is_any?(*classes) ⇒ TrueClass, FalseClass
Checks if an object is an instance of any of the given classes
22 23 24 |
# File 'lib/sinclair/core_ext/object.rb', line 22 def is_any?(*classes) classes.any?(method(:is_a?)) end |
#map_and_find {|*args| ... } ⇒ ::Object
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
58 59 60 61 62 63 64 |
# File 'lib/sinclair/core_ext/object.rb', line 58 def map_and_find mapped = nil find do |*args| mapped = yield(*args) end mapped || nil end |