るりまサーチ

最速Rubyリファレンスマニュアル検索!
99件ヒット [1-99件を表示] (0.045秒)
トップページ > クエリ:String#tr[x] > クエリ:type[x] > クラス:Struct[x]

別のキーワード

  1. << rexml::attribute#name
  2. add rexml::attribute#name
  3. handle_interrupt thread#raise
  4. service drb::extserv#stop_service
  5. inspect? irb::context#inspect_mode

ライブラリ

キーワード

検索結果

Struct#inspect -> String (3203.0)

self の内容を人間に読みやすい文字列にして返します。

...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =...
...Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.inspect # => "#<struct Customer name=\"Joe Smith\", address=\"123 Maple, Anytown NC\", zip=12345>"
//}...

Struct#to_s -> String (3203.0)

self の内容を人間に読みやすい文字列にして返します。

...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =...
...Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.inspect # => "#<struct Customer name=\"Joe Smith\", address=\"123 Maple, Anytown NC\", zip=12345>"
//}...

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

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

...引数はそのまま 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::GeneratorMe...

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

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

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

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

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

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

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

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

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

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

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

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

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

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

絞り込み条件を変える

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

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

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

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

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...した。
メンバ名に String を指定できるのは後方互換性のためだと考えた方が良いでしょう。
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。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) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...

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

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

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

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

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...した。
メンバ名に String を指定できるのは後方互換性のためだと考えた方が良いでしょう。
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。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) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...

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

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

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

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

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...した。
メンバ名に String を指定できるのは後方互換性のためだと考えた方が良いでしょう。
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定...
...ord_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...

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

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

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

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

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...した。
メンバ名に String を指定できるのは後方互換性のためだと考えた方が良いでしょう。
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定...
...ord_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...

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

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

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

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

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...した。
メンバ名に String を指定できるのは後方互換性のためだと考えた方が良いでしょう。
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定...
...します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。
Ruby 3.1 では互換性に影響のある使い方をしたときに警告が出るため、
従来の挙動を期待する構造...
...* true: キーワード引数のみ使用できる
* false: キーワード引数は使用できず、位置引数のみ使用できる


//emlist[例][ruby]{
Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point...

絞り込み条件を変える

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

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

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

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

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...した。
メンバ名に String を指定できるのは後方互換性のためだと考えた方が良いでしょう。
したがって、メンバ名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定...
...します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。
Ruby 3.1 では互換性に影響のある使い方をしたときに警告が出るため、
従来の挙動を期待する構造...
...* true: キーワード引数のみ使用できる
* false: キーワード引数は使用できず、位置引数のみ使用できる


//emlist[例][ruby]{
Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point...

Struct#[](member) -> object (3013.0)

構造体のメンバの値を返します。

...デックスを指定します。
Symbol, String でメンバの名前を指定します。

@raise IndexError member が整数で存在しないメンバを指定した場合に発生します。

@raise NameError member が String, Symbol で存在しないメンバを指定した場...
...n struct (NameError)
p obj[0] # => "FOO"
p obj[1] # => "BAR"
p obj[-1] # => "BAR" # Array のように負のインデックスも指定できます。
p obj[2] # => in `[]': offset 2 too large for struct(size:2) (IndexError)
//}

[注意] 本メソッドの記述は Str...
...uct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。...

Struct#[]=(member, value) (3013.0)

構造体の member で指定されたメンバの値を value にして value を返します。

...Symbol, String でメンバの名前を指定します。

@param value メンバに設定する値を指定します。

@raise IndexError member が整数で存在しないメンバを指定した場合に発生します。

@raise NameError member が String, Symbol で存在しな...
...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =...