るりまサーチ

最速Rubyリファレンスマニュアル検索!
269件ヒット [1-100件を表示] (0.031秒)
トップページ > クラス:Struct[x] > クエリ:struct[x] > クエリ:new[x] > 種類:インスタンスメソッド[x]

別のキーワード

  1. mkmf have_struct_member
  2. struct []
  3. struct each
  4. struct select

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

Struct#to_h -> Hash (9062.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

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

ブロックを...
...omer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :address=>"123 Maple, Anytown NC123 Maple, Anytown NC", :zip=>24690}
//}

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

Struct#to_h {|member, value| block } -> Hash (9062.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

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

ブロックを...
...omer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :address=>"123 Maple, Anytown NC123 Maple, Anytown NC", :zip=>24690}
//}

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

Struct#==(other) -> bool (9056.0)

self と other のクラスが同じであり、各メンバが == メソッドで比較して等しい場合に true を返します。そうでない場合に false を返します。

...//emlist[例][ruby]{
Dog = Struct.new(:name, :age)
dog1 = Dog.new("fred", 5)
dog2 = Dog.new("fred", 5)

p dog1 == dog2 #=> true
p dog1.eql?(dog2) #=> true
p dog1.equal?(dog2) #=> false
//}

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

@see Struct#eql?...

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

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

...指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
obj = Foo.new('FOO', 'BAR')
p obj[:foo] # => "FOO"
p obj['bar'] # => "BAR"
# p obj[:baz] # => in `[]': no member 'baz' in struct (NameError)
p obj[0] # => "FOO"
p obj[1] # => "BAR"
p o...
...p obj[2] # => in `[]': offset 2 too large for struct(size:2) (IndexError)
//}

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

Struct#eql?(other) -> bool (9056.0)

self と other のクラスが同じであり、各メンバが eql? メソッドで比較して等しい場合に true を返します。そうでない場合に false を返します。

...//emlist[例][ruby]{
Dog = Struct.new(:name, :age)
dog1 = Dog.new("fred", 5)
dog2 = Dog.new("fred", 5)

p dog1 == dog2 #=> true
p dog1.eql?(dog2) #=> true
p dog1.equal?(dog2) #=> false
//}

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

@see Struct#==...

絞り込み条件を変える

Struct#inspect -> String (9050.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 (9050.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#[]=(member, value) (9044.0)

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

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

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

Struct#each -> Enumerator (9044.0)

構造体の各メンバに対して繰り返します。

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

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

Struct#each {|value| ... } -> self (9044.0)

構造体の各メンバに対して繰り返します。

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

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

絞り込み条件を変える

<< 1 2 3 > >>