Module: RgssDb::Jsonable

Overview

Jsonable mixin

Instance Method Summary collapse

Instance Method Details

#as_jsonHash

Returns this instance as a json-ready hash

Returns:

  • (Hash)


13
14
15
16
17
18
19
20
21
22
# File 'lib/rgss_db/model/mixins/jsonable.rb', line 13

def as_json
  hash = {}
  hash.store(JSON.create_id, self.class.name)
  instance_variables.each do |ivar|
    ivar_id = ivar.to_s.delete("@")
    ivar_value = instance_variable_get(ivar)
    hash.store(ivar_id, ivar_value)
  end
  hash
end

#to_json(*args) ⇒ String

Converts this instance to a JSON string

Parameters:

  • args (Array)

    Arguments

Returns:

  • (String)


31
32
33
# File 'lib/rgss_db/model/mixins/jsonable.rb', line 31

def to_json(*args)
  as_json.to_json(*args)
end