Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/core_ext/object.rb
Defined Under Namespace
Classes: TryObject
Instance Method Summary collapse
-
#try_call(*args, &block) ⇒ Object
Tries to call the given method if it exists.
Instance Method Details
#try_call(*args, &block) ⇒ Object
Tries to call the given method if it exists. If the method doesn’t exist, it will just return nil
26 27 28 29 30 31 32 |
# File 'lib/core_ext/object.rb', line 26 def try_call(*args, &block) if args.empty? TryObject.new(self) else self.send(*args, &block) if(self.respond_to?(args.first)) end end |