Class: LunchMoney::Objects::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/lunchmoney/objects/object.rb

Overview

Base data object for the objects returned and used when calling the LunchMoney API

Instance Method Summary collapse

Instance Method Details

#serialize(symbolize_keys: false) ⇒ Hash{String, Symbol => T.untyped}

Parameters:

  • symbolize_keys (Boolean) (defaults to: false)

Returns:

  • (Hash{String, Symbol => T.untyped})


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lunchmoney/objects/object.rb', line 10

def serialize(symbolize_keys: false)
  output = {}

  instance_variables.each do |ivar|
    key_string = ivar.to_s.delete_prefix("@")
    key = symbolize_keys ? key_string.to_sym : key_string
    output[key] = instance_variable_get(ivar)
  end

  output
end