るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

オブジェクト

キーワード

検索結果

<< 1 2 > >>

Struct.new(*args, keyword_init: nil) -> Class (18316.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.new(x: 1, y: 2, z: 3...
...Struct.new(:x, :y, keyword_init: nil)
Point2.new(1, 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1, y: 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1) # => #<struct Point2 x=1, y=nil>
Point2.new(y: 2) # => #<struct Point2 x=nil, y=2>
Point2.new(x: 1,...

Struct.new(*args, keyword_init: nil) {|subclass| block } -> Class (18316.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.new(x: 1, y: 2, z: 3...
...Struct.new(:x, :y, keyword_init: nil)
Point2.new(1, 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1, y: 2) # => #<struct Point2 x=1, y=2>
Point2.new(x: 1) # => #<struct Point2 x=1, y=nil>
Point2.new(y: 2) # => #<struct Point2 x=nil, y=2>
Point2.new(x: 1,...

Psych::Nodes::Document.new(version=[], tag_directives=[], implicit=false) -> Psych::Nodes::Document (18308.0)

Document オブジェクトを生成します。

...YAML 1.1 のドキュメントで、
tag directive を1つ持ち、 implicit にドキュメントが開始
している Document オブジェクトを生成しています。

Psych::Nodes::Document.new(
[1,1],
tenderlovemaking.com,2009:",
true)

@see Psych::Handler#start_document...

Struct.new(*args, keyword_init: nil) -> Class (18232.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...{
Point = Struct.new(:x, :y)
Point.new(x: 1, y: 2) # => #<struct Point x={:x=>1, :y=>2}, y=nil>
# warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).

# keywor...

Struct.new(*args, keyword_init: nil) {|subclass| block } -> Class (18232.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...{
Point = Struct.new(:x, :y)
Point.new(x: 1, y: 2) # => #<struct Point x={:x=>1, :y=>2}, y=nil>
# warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).

# keywor...

絞り込み条件を変える

Data.[](**kwargs) -> Data (18217.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2

p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}

new
に渡す引数の数がメンバの数より多い場合は new でエラーになります。

new
に渡す引数の数がメンバの数より少ない場合は new では...
...のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ...
...alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown...

Data.[](*args) -> Data (18217.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2

p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}

new
に渡す引数の数がメンバの数より多い場合は new でエラーになります。

new
に渡す引数の数がメンバの数より少ない場合は new では...
...のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ...
...alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown...

Data.new(**kwargs) -> Data (18217.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2

p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}

new
に渡す引数の数がメンバの数より多い場合は new でエラーになります。

new
に渡す引数の数がメンバの数より少ない場合は new では...
...のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ...
...alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown...

Data.new(*args) -> Data (18217.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2

p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}

new
に渡す引数の数がメンバの数より多い場合は new でエラーになります。

new
に渡す引数の数がメンバの数より少ない場合は new では...
...のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ...
...alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown...

Struct.new(*args) -> Class (18196.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

絞り込み条件を変える

Struct.new(*args) {|subclass| block } -> Class (18196.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

Struct.new(*args, keyword_init: false) -> Class (18196.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

Struct.new(*args, keyword_init: false) {|subclass| block } -> Class (18196.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...では構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合...
...emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unkn...
...ラーになります。

//emlist[例][ruby]{
p Struct.new('foo', 'bar')
# => -:1:in `new': identifier foo needs to be constant (NameError)
//}

また args[1..-1] は、Symbol か String で指定します。

//emlist[例][ruby]{
p Struct.new("Foo", :foo, :bar) # => Struct::Foo
//}

=== 第一...

Struct.[](*args) -> Struct (18151.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct.new(*args) -> Struct (18151.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

絞り込み条件を変える

Struct.[](*args) -> Struct (18137.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct.new(*args) -> Struct (18137.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Hash.new(ifnone = nil) -> Hash (18136.0)

空の新しいハッシュを生成します。ifnone はキーに対 応する値が存在しない時のデフォルト値です。設定したデフォルト値はHash#defaultで参照できます。

...略した Hash.new は {} と同じです。

デフォルト値として、毎回同一のオブジェクトifnoneを返します。
それにより、一箇所のデフォルト値の変更が他の値のデフォルト値にも影響します。

//emlist[][ruby]{
h = Hash.new([])
h[0] << 0
h[1]...
...uby]{
h = Hash.new([])

p h[1] #=> []
p h[1].object_id #=> 6127150
p h[1] << "bar" #=> ["bar"]
p h[1] #=> ["bar"]

p h[2] #=> ["bar"]
p h[2].object_id #=> 6127150

p h #=> {}


h = Hash.new([].freeze)
h[0] +...

Struct.[](*args) -> Struct (18131.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct.new(*args) -> Struct (18131.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

絞り込み条件を変える

Hash.new {|hash, key| ... } -> Hash (18126.0)

空の新しいハッシュを生成します。ブロックの評価結果がデフォルト値になりま す。設定したデフォルト値はHash#default_procで参照できます。

...ト値は全部同一のオブジェクトなので、
# 破壊的変更によって他のキーに対応する値も変更されます。
h = Hash.new("foo")

p h[1] #=> "foo"
p h[1].object_id #=> 6127170
p h[1] << "bar" #=> "foobar"
p h[1] #=> "foob...
...値がまだ無いキーが呼び出される度に
# ブロックを評価するので、全て別のオブジェクトになります。
h = Hash.new {|hash, key| hash[key] = "foo"}

p h[1] #=> "foo"
p h[1].object_id #=> 6126900
p h[1] << "bar" #=> "foobar"
p h[1]...
...#=> {1=>"foobar", 2=>"foo"}

# 値が設定されていないときに(fetchのように)例外をあげるようにもできる
h = Hash.new {|hash, key|
raise(IndexError, "hash[#{key}] has no value")
}
h[1]
# エラー hash[1] has no value (IndexError)
//}...

ThreadsWait.new(*threads) -> ThreadsWait (18120.0)

指定されたスレッドの終了をまつための、スレッド同期オブジェクトをつくります。

...レッドを一つもしくは複数指定します。

使用例
require 'thwait'

threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}

thall = ThreadsWait.new(*threads)
thall.all_waits{|th|
printf("end %s\n", th.inspect)
}

# 出力例
#=>...

Hash.[](*key_and_value) -> Hash (18107.0)

新しいハッシュを生成します。 引数は必ず偶数個指定しなければなりません。奇数番目がキー、偶数番目が値になります。

...番目が値になります。

このメソッドでは生成するハッシュにデフォルト値を指定することはできません。
Hash.newを使うか、Hash#default=で後から指定してください。

@param key_and_value 生成するハッシュのキーと値の組です。必...
...す。

(1) [キー, 値, ...] の配列からハッシュへ

//emlist[][ruby]{
ary = [1,"a", 2,"b", 3,["c"]]
p Hash[*ary] # => {1=>"a", 2=>"b", 3=>["c"]}
//}

(2) キーと値のペアの配列からハッシュへ

//emlist[][ruby]{
alist = [[1,"a"], [2,"b"], [3,["c"]]]
p alist.flatten(1) # => [...
...ュへ

//emlist[][ruby]{
keys = [1, 2, 3]
vals = ["a", "b", ["c"]]
alist = keys.zip(vals) # あるいは alist = [keys,vals].transpose
p alist # => [[1, "a"], [2, "b"], [3, ["c"]]]
p Hash[alist] # => {1=>"a", 2=>"b", 3=>["c"]}
//}

(4) キーや値が配列の場合

//emlist[][ruby]{
alist =...
<< 1 2 > >>