るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

検索結果

TracePoint.new(*events) {|obj| ... } -> TracePoint (18198.0)

新しい TracePoint オブジェクトを作成して返します。トレースを有効 にするには TracePoint#enable を実行してください。

...b で実行した場合][ruby]{
trace = TracePoint.new(:call) do |tp|
p [tp.lineno, tp.defined_class, tp.method_id, tp.event]
end
# => #<TracePoint:0x007f17372cdb20>

trace.enable
# => false

puts "Hello, TracePoint!"
# ...
# [69, IRB::Notifier::AbstractNotifier, :printf, :call]
# ...
//}

...
...レースを無効にするには TracePoint#disable を実行してください。

//emlist[][ruby]{
trace.disable
//}

@param events トレースするイベントを String か Symbol で任
意の数指定します。

: :line

式の評価。

: :class

クラス定義、特...
...への突入。

: :end

クラス定義、特異クラス定義、モジュール定義の終了。

: :call

Ruby
で記述されたメソッドの呼び出し。

: :return

Ruby
で記述されたメソッド呼び出しからのリターン。

: :c_call

C で記述されたメソッ...

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定します。
@param keyword_init 構造体クラスのインスタンスを生成する際に、キーワード引数を...
...[例][ruby]{
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...

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定します。
@param keyword_init 構造体クラスのインスタンスを生成する際に、キーワード引数を...
...[例][ruby]{
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...

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...args 構造体を定義するための可変長引数。String または Symbol を指定します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。
Ruby
3.1 では互換性に影響のある使い方をした...
...い。

//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) # ArgumentE...

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...args 構造体を定義するための可変長引数。String または Symbol を指定します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。
Ruby
3.1 では互換性に影響のある使い方をした...
...い。

//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) # ArgumentE...

絞り込み条件を変える

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...可変長引数。String または Symbol を指定します。

//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) # => #<s...
...oint.new(z: 3) # ArgumentError (unknown keywords: z)
//}


=== 第一引数が String の場合
args[0] が String の場合、クラス名になるので、大文字で始まる必要
があります。つまり、以下のような指定はエラーになります。

//emlist[例][ruby]{
p...

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...可変長引数。String または Symbol を指定します。

//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) # => #<s...
...oint.new(z: 3) # ArgumentError (unknown keywords: z)
//}


=== 第一引数が String の場合
args[0] が String の場合、クラス名になるので、大文字で始まる必要
があります。つまり、以下のような指定はエラーになります。

//emlist[例][ruby]{
p...

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...変長引数。String または Symbol を指定します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。

//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 (unknown keywords: z)
//}


=== 第一引数が String の場合
args[0] が String の場合、クラス名になるので...

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

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

...mlist[例][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" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定...
...変長引数。String または Symbol を指定します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。

//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 (unknown keywords: z)
//}


=== 第一引数が String の場合
args[0] が String の場合、クラス名になるので...

Struct.new(*args) -> Struct (15186.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 (86.0)

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

...なければ nil です。

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

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

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