Class: ConvenientService::Support::SafeMethod Private

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/support/safe_method.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method, default: nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • object (Object)

    Can be any type.

  • method (Symbol, String)
  • default (Object, nil) (defaults to: nil)

    Can be any type.

Since:

  • 1.0.0



35
36
37
38
39
# File 'lib/convenient_service/support/safe_method.rb', line 35

def initialize(object, method, default: nil)
  @object = object
  @method = method
  @default = default
end

Instance Attribute Details

#defaultObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



27
28
29
# File 'lib/convenient_service/support/safe_method.rb', line 27

def default
  @default
end

#methodObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



21
22
23
# File 'lib/convenient_service/support/safe_method.rb', line 21

def method
  @method
end

#objectObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



15
16
17
# File 'lib/convenient_service/support/safe_method.rb', line 15

def object
  @object
end

Instance Method Details

#call(*args, **kwargs, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Can be any type.

Parameters:

  • args (Array<Object>)
  • kwargs (Hash{Symbol => Object})
  • block (Proc, nil)

Returns:

  • (Object)

    Can be any type.

Since:

  • 1.0.0



47
48
49
50
51
# File 'lib/convenient_service/support/safe_method.rb', line 47

def call(*args, **kwargs, &block)
  return default unless method_defined?

  object.__send__(method, *args, **kwargs, &block)
end