るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.245秒)
トップページ > クエリ:i[x] > クエリ:-[x] > クエリ:r[x] > クエリ:String[x] > クエリ:to[x] > クエリ:create_id[x]

別のキーワード

  1. _builtin to_r
  2. string []=
  3. string slice
  4. string slice!
  5. string []

ライブラリ

モジュール

検索結果

JSON.create_id -> String (30520.0)

json_create メソッドで使用するクラスを決定するために使用する値を返します。

...json_create メソッドで使用するクラスを決定するために使用する値を返します。

デフォルトは "json_class" です。

//emlist[例][ruby]{
r
equire "json"

class User
attr :id, :name
def initialize(id, name)
@id, @name = id, name
end

def self.json_create(o...
...new(object['id'], object["name"])
end

def as_json(*)
{
JSON.create_id => self.class.name,
"id" => id,
"name" => name,
}
end

def to_json(*)
as_json.to_json
end
end

json = JSON.generate(User.new(1, "tanaka"))
json # => "{\"json_class\":\"User\",\"id\":1,\"nam...
...e\":\"tanaka\"}"
JSON.parse(json, create_additions: true)
# => #<User:0x0000557709b269e0 @id=1, @name="tanaka">
//}...