Class: CoreLibrary::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic-core/types/sdk/base_model.rb

Overview

The Base class of all custom types.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object

Use to allow additional model properties.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/apimatic-core/types/sdk/base_model.rb', line 5

def method_missing(method_sym, *arguments, &block)
  method = method_sym.to_s
  if method.end_with? '='
    instance_variable_set(format('@%s', [method.chomp('=')]),
                          arguments.first)
  elsif instance_variable_defined?("@#{method}") && arguments.empty?
    instance_variable_get("@#{method}")
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(method_sym, include_private = false) ⇒ Boolean

Override for additional model properties.

Returns:

  • (Boolean)


18
19
20
# File 'lib/apimatic-core/types/sdk/base_model.rb', line 18

def respond_to_missing?(method_sym, include_private = false)
  instance_variable_defined?("@#{method_sym}") ? true : super
end