るりまサーチ (Ruby 2.5.0)

最速Rubyリファレンスマニュアル検索!
30件ヒット [1-30件を表示] (0.034秒)

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

検索結果

JSON::State#configure(options = {}) -> self (64.0)

与えられたハッシュで自身を設定します。

...ーについては JSON::State.new を参照してください。

@param options このオブジェクトの設定をするためのハッシュを指定します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(indent: "\t")
json
_state.indent # => "\t"
JSON
.generate({key1: "va...
...lue1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"

json
_state.configure(indent: " ")
json
_state.indent # => " "
JSON
.generate({key1: "value1", key2: "value2"}, json_state)
# => "{ \"key1\":\"value1\", \"key2\":\"value2\"}"
//}

@see JSON::State.new...

JSON::State#merge(options = {}) -> self (64.0)

与えられたハッシュで自身を設定します。

...ーについては JSON::State.new を参照してください。

@param options このオブジェクトの設定をするためのハッシュを指定します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(indent: "\t")
json
_state.indent # => "\t"
JSON
.generate({key1: "va...
...lue1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"

json
_state.configure(indent: " ")
json
_state.indent # => " "
JSON
.generate({key1: "value1", key2: "value2"}, json_state)
# => "{ \"key1\":\"value1\", \"key2\":\"value2\"}"
//}

@see JSON::State.new...

JSON::Generator::GeneratorMethods::Object#to_json(state_or_hash = nil) -> String (46.0)

自身を to_s で文字列にした結果を JSON 形式の文字列に変換して返します。

...した結果を JSON 形式の文字列に変換して返します。

このメソッドはあるオブジェクトに to_json メソッドが定義されていない場合に使用する
フォールバックのためのメソッドです。

@param state_or_hash 生成する JSON 形式の文字...
...をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new の引数と同じ Hash を
指定します。

//emlist[例][ruby]{
require "json"

class Person
attr :name, :age

def initialize(name, ag...
...e)
@name, @age = name, age
end
end

tanaka = Person.new("tanaka", 29)

tanaka.to_json # => "\"#<Person:0x00007ffdec0167c8>\""
tanaka.method(:to_json).owner # => JSON::Ext::Generator::GeneratorMethods::Object
//}...

JSON::State#allow_nan? -> bool (46.0)

NaN, Infinity, -Infinity を生成できる場合、真を返します。 そうでない場合は偽を返します。

...finity を生成できる場合、真を返します。
そうでない場合は偽を返します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new({})
json
_state.allow_nan? # => false
json
_state = JSON::State.new(allow_nan: true)
json
_state.allow_nan? # => true
//}

@see 4627...

JSON::State#array_nl -> String (46.0)

JSON の配列の後に出力する文字列を返します。

...
JSON
の配列の後に出力する文字列を返します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new({})
json
_state.array_nl # => ""
json
_state = JSON::State.new(array_nl: "\n")
json
_state.array_nl # => "\n"
//}...

絞り込み条件を変える

JSON::State#check_circular? -> bool (46.0)

循環参照のチェックを行う場合は、真を返します。 そうでない場合は偽を返します。

...y]{
require "json"

a = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[0]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
s = JSON.state.new
begin
JSON
.generate(a, s)
rescue JSON::NestingErr...
...or => e
[e, s.max_nesting, s.check_circular?] # => [#<JSON::NestingError: nesting of 100 is too deep>, 100, true]
end
//}

//emlist[例 ネストをチェックしないケース][ruby]{
require "json"

a = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[...
...[[[[[[[[[[0]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
s2 = JSON.state.new(max_nesting: 0)
json
= JSON.generate(a, s2)
[json, s2.max_nesting, s2.check_circular?] # => ["[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[...

JSON::State#max_nesting -> Integer (46.0)

生成される JSON 形式の文字列のネストの深さの最大値を返します。

... JSON 形式の文字列のネストの深さの最大値を返します。

この値がゼロである場合は、ネストの深さのチェックを行いません。

//emlist[例 ネストの深さチェックを行う][ruby]{
require "json"

json
_state = JSON::State.new(max_nesting: 2)
json
_s...
...# => 2
JSON
.generate([[]], json_state)
JSON
.generate([[[]]], json_state) # => JSON::NestingError
//}

//emlist[例 ネストの深さチェックを行わない][ruby]{
require "json"

json
_state = JSON::State.new(max_nesting: 0)
json
_state.max_nesting # => 0
JSON
.generate([[[[[...
...[[[[[]]]]]]]]]], json_state)
//}...

JSON::State#object_nl -> String (46.0)

JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列を返します。

...
JSON
形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列を返します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(object_nl: "")
json
_state.object_nl # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }...
...], json_state)
# => [1,2,{"name":"tanaka","age":19}]

json
_state = JSON::State.new(object_nl: "\n")
json
_state.object_nl # => "\n"
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)

# => [1,2,{
# "name":"tanaka",
# "age":19
# }]
//}...

JSON::State#space -> String (46.0)

JSON 形式の文字列のトークン間に挿入する文字列を返します。

...
JSON
形式の文字列のトークン間に挿入する文字列を返します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(space: "")
json
_state.space # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age"...
...:19}]

json
_state = JSON::State.new(space: "\t")
json
_state.space # => "\t"
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name": "tanaka","age": 19}]
//}...

JSON::State#space_before -> String (46.0)

JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の 前に挿入する文字列を返します。

...
JSON
形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の
前に挿入する文字列を返します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(space_before: "")
json
_state.space_before # => ""
puts JSON.generate([1, 2, { n...
...ame: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]

json
_state = JSON::State.new(space_before: " ")
json
_state.space_before # => " "
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name" :"tanaka","age" :19}]
//}...

絞り込み条件を変える

Struct#to_json(*args) -> String (43.0)

自身を JSON 形式の文字列に変換して返します。

...自身を JSON 形式の文字列に変換して返します。

内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。

@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡...
...されます。

//emlist[例][ruby]{
require "json/add/core"

Person = Struct.new(:name, :age)
Person.new("tanaka", 29).to_json # => "{\"json_class\":\"Person\",\"v\":[\"tanaka\",29]}"
//}

@see JSON::Generator::GeneratorMethods::Hash#to_json...

JSON::Generator::GeneratorMethods::Array#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...自身から生成した JSON 形式の文字列を返します。

@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new の引数と同じ Hash を...
...指定します。

//emlist[例][ruby]{
require "json"

[1, 2, 3].to_json # => "[1,2,3]"
//}...

JSON::Generator::GeneratorMethods::FalseClass#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...ら生成した JSON 形式の文字列を返します。

"false" という文字列を返します。

@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new...
...の引数と同じ Hash を
指定します。

//emlist[例][ruby]{
require "json"

false.to_json # => "false"
//}...

JSON::Generator::GeneratorMethods::Float#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...自身から生成した JSON 形式の文字列を返します。

@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new の引数と同じ Hash を...
...指定します。

//emlist[例][ruby]{
require "json"

(1.0).to_json # => "1.0"
//}...

JSON::Generator::GeneratorMethods::Hash#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...自身から生成した JSON 形式の文字列を返します。

@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new の引数と同じ Hash を...
...指定します。

//emlist[例][ruby]{
require "json"

person = { "name" => "tanaka", "age" => 19 }
person.to_json # => "{\"name\":\"tanaka\",\"age\":19}"
//}...

絞り込み条件を変える

JSON::Generator::GeneratorMethods::Integer#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...自身から生成した JSON 形式の文字列を返します。

@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new の引数と同じ Hash を...
...指定します。

//emlist[例][ruby]{
require "json"

10.to_json # => "10"
//}...

JSON::Generator::GeneratorMethods::NilClass#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...ら生成した JSON 形式の文字列を返します。

"null" という文字列を返します。

@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new の...
...引数と同じ Hash を
指定します。

//emlist[例][ruby]{
require "json"

nil.to_json # => "null"
//}...

JSON::Generator::GeneratorMethods::String#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...ら生成した JSON 形式の文字列を返します。

自身のエンコードは UTF-8 であるべきです。
"\u????" のように UTF-16 ビッグエンディアンでエンコードされた文字列を返すことがあります。

@param state_or_hash 生成する JSON 形式の文字...
... JSON::State のインスタンスか、
JSON
::State.new の引数と同じ Hash を
指定します。

//emlist[例][ruby]{
require "json"

puts "test".to_json # => "test"
puts '"'.to_json #...
...=> "\""
puts "\\".to_json # => "\\"
puts "𤘩宮城".to_json(ascii_only: true) # => "\ud851\ude29\u5bae\u57ce"
//}...

JSON::Generator::GeneratorMethods::TrueClass#to_json(state_or_hash = nil) -> String (28.0)

自身から生成した JSON 形式の文字列を返します。

...ら生成した JSON 形式の文字列を返します。

"true" という文字列を返します。

@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
JSON::State のインスタンスか、
JSON
::State.new の...
...引数と同じ Hash を
指定します。

//emlist[例][ruby]{
require "json"

true.to_json # => "true"
//}...

JSON::Parser#parse -> object (28.0)

現在のソースをパースして結果を Ruby のオブジェクトとして返します。

...uby のオブジェクトとして返します。

//emlist[例][ruby]{
require 'json'

class Person
attr_accessor :name, :age

def []=(key, value)
instance_variable_set("@#{key}", value)
end
end

parser = JSON::Parser.new(DATA.read, object_class: Person)
person = parser.parse
person.class...
...# => Person
person.name # => "tanaka"
person.age # => 20

__END__
{
"name":"tanaka",
"age":20
}
//}

@see JSON::Parser#source...

絞り込み条件を変える

JSON::Parser#source -> String (28.0)

現在のソースのコピーを返します。

...現在のソースのコピーを返します。

//emlist[例][ruby]{
require 'json'

parser = JSON::Parser.new(DATA.read)
print parser.source

# => {
# => "Tanaka": {
# => "name":"tanaka",
# => "age":20
# => },
# => "Suzuki": {
# => "name":"suzuki",
# => "age":25
# => }
#...

JSON::State#array_nl=(str) (28.0)

JSON の配列の後に出力する文字列をセットします。

...
JSON
の配列の後に出力する文字列をセットします。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new({})
json
_state.array_nl # => ""
json
_state.array_nl = "\n"
json
_state.array_nl # => "\n"
//}...

JSON::State#indent -> String (28.0)

インデントに使用する文字列を返します。

...インデントに使用する文字列を返します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(indent: "\t")
json
_state.indent # => "\t"
JSON
.generate({key1: "value1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"
//}...

JSON::State#indent=(string) (28.0)

インデントに使用する文字列をセットします。

...ruby]{
require "json"

json
_state = JSON::State.new(indent: "\t")
json
_state.indent # => "\t"
JSON
.generate({key1: "value1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"
json
_state.indent = " "
JSON
.generate({key1: "value1", key2: "value2"}, json_state)
# => "{...

JSON::State#max_nesting=(depth) (28.0)

生成される JSON 形式の文字列のネストの深さの最大値をセットします。

...生成される JSON 形式の文字列のネストの深さの最大値をセットします。

この値にゼロをセットすると、ネストの深さのチェックを行いません。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(max_nesting: 2)
json
_state.max_nestin...
...g # => 2
JSON
.generate([[]], json_state)
json
_state.max_nesting = 3
json
_state.max_nesting # => 3
JSON
.generate([[[[]]]], json_state) # => JSON::NestingError
//}...

絞り込み条件を変える

JSON::State#object_nl=(string) (28.0)

JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列をセットします。

...
JSON
形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列をセットします。

@param string JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列を指定します。

//emlist[例][ruby]{
require...
..."json"

json
_state = JSON::State.new(object_nl: "")
json
_state.object_nl # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]

json
_state.object_nl = "\n"
json
_state.object_nl # => "\n"
puts JSON.generate([1, 2, {...
...name: "tanaka", age: 19 }], json_state)
# => [1,2,{
# "name":"tanaka",
# "age":19
# }]
//}...

JSON::State#space=(string) (28.0)

JSON 形式の文字列のトークン間に挿入する文字列をセットします。

...
JSON
形式の文字列のトークン間に挿入する文字列をセットします。

@param string JSON 形式の文字列のトークン間に挿入する文字列を指定します。

//emlist[例][ruby]{
require "json"

json
_state = JSON::State.new(space: "")
json
_state.space...
...# => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]

json
_state.space = "\t"
json
_state.space # => "\t"
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name": "tanaka","age": 19}]
//}...

JSON::State#space_before=(string) (28.0)

JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の 前に挿入する文字列をセットします。

...
JSON
形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の
前に挿入する文字列をセットします。

@param string JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の
前に挿入する文字列...
...uire "json"

json
_state = JSON::State.new(space_before: "")
json
_state.space_before # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]

json
_state.space_before = " "
json
_state.space_before # => " "
puts JSON.gene...
...rate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name" :"tanaka","age" :19}]
//}...

JSON::State#to_h -> Hash (28.0)

自身をハッシュに変換します。

...自身をハッシュに変換します。

//emlist[例][ruby]{
require "json"
require "pp"

json
_state = JSON::State.new
pp json_state.to_h

# => {:indent=>"",
# :space=>"",
# :space_before=>"",
# :object_nl=>"",
# :array_nl=>"",
# :allow_nan=>false,
# :ascii_only=>false,...

JSON::State#to_hash -> Hash (28.0)

自身をハッシュに変換します。

...自身をハッシュに変換します。

//emlist[例][ruby]{
require "json"
require "pp"

json
_state = JSON::State.new
pp json_state.to_h

# => {:indent=>"",
# :space=>"",
# :space_before=>"",
# :object_nl=>"",
# :array_nl=>"",
# :allow_nan=>false,
# :ascii_only=>false,...

絞り込み条件を変える