Class: ConvenientService::Support::SafeMethod
- Inherits:
-
Object
- Object
- ConvenientService::Support::SafeMethod
- Defined in:
- lib/convenient_service/support/safe_method.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#call(*args, **kwargs, &block) ⇒ Object
Can be any type.
- #initialize(object, method, default: nil) ⇒ void constructor
Constructor Details
#initialize(object, method, default: nil) ⇒ void
30 31 32 33 34 |
# File 'lib/convenient_service/support/safe_method.rb', line 30 def initialize(object, method, default: nil) @object = object @method = method @default = default end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
22 23 24 |
# File 'lib/convenient_service/support/safe_method.rb', line 22 def default @default end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
16 17 18 |
# File 'lib/convenient_service/support/safe_method.rb', line 16 def method @method end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
10 11 12 |
# File 'lib/convenient_service/support/safe_method.rb', line 10 def object @object end |
Instance Method Details
#call(*args, **kwargs, &block) ⇒ Object
Returns Can be any type.
42 43 44 45 46 |
# File 'lib/convenient_service/support/safe_method.rb', line 42 def call(*args, **kwargs, &block) return default unless method_defined? object.__send__(method, *args, **kwargs, &block) end |