Class: EasyPost::Models::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/easypost/models/base.rb

Overview

The base class for all JSON objects in the library.

Direct Known Subclasses

EasyPostObject

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Object

Returns a new instance of Object.



7
8
9
10
# File 'lib/easypost/models/base.rb', line 7

def initialize(data)
  @values = data
  add_properties(data)
end

Instance Method Details

#[](key) ⇒ Object

Get element of an array.



23
24
25
# File 'lib/easypost/models/base.rb', line 23

def [](key)
  @values[key.to_s]
end

#[]=(key, value) ⇒ Object

Set the element of an array.



28
29
30
# File 'lib/easypost/models/base.rb', line 28

def []=(key, value)
  send(:"#{key}=", value)
end

#to_hashObject

Convert object to hash



18
19
20
# File 'lib/easypost/models/base.rb', line 18

def to_hash
  JSON.parse(JSON.dump(@values))
end

#to_s(*_args) ⇒ Object

Convert to a string.



13
14
15
# File 'lib/easypost/models/base.rb', line 13

def to_s(*_args)
  JSON.dump(@values)
end