Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/utilities/object.rb
Instance Method Summary collapse
-
#attempt(method, *args, &block) ⇒ Object
Attempts to call a method on given object.
- #is_any?(*args) ⇒ Boolean
- #within?(enumerable) ⇒ Boolean
Instance Method Details
#attempt(method, *args, &block) ⇒ Object
Attempts to call a method on given object. If it fails (nil or NoMethodError), returns nil
11 12 13 14 15 16 17 |
# File 'lib/utilities/object.rb', line 11 def attempt method, *args, &block begin self.try(method, *args, &block) rescue NoMethodError nil end end |
#is_any?(*args) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/utilities/object.rb', line 19 def is_any?(*args) args.any? do |klass| self.is_a? klass end end |
#within?(enumerable) ⇒ Boolean
2 3 4 5 6 7 8 |
# File 'lib/utilities/object.rb', line 2 def within? enumerable if enumerable.is_a? Range enumerable.cover?(self) else enumerable.min <= self && self <= enumerable.max end end |