種類
- インスタンスメソッド (25)
- 特異メソッド (6)
検索結果
先頭5件
-
Struct
. new(*args , keyword _ init: nil) -> Class (63610.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "....../emlist[例][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.n......words: z)
Point2 = 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... -
Struct
. new(*args , keyword _ init: nil) {|subclass| block } -> Class (63610.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "....../emlist[例][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.n......words: z)
Point2 = 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... -
Struct
. [](*args) -> Struct (63475.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 (63475.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
# [](member) -> object (63118.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
. keyword _ init? -> bool | nil (63112.0) -
(このメソッドは Struct の下位クラスにのみ定義されています) 構造体が作成されたときに keyword_init: true を指定されていたら true を返します。 false を指定されていたら false を返します。 それ以外の場合は nil を返します。
...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体が作成されたときに keyword_init: true を指定されていたら true を返します。
false を指定されていたら false を返します。
それ以外の場合は nil を返します。......//emlist[例][ruby]{
Foo = Struct.new(:a)
Foo.keyword_init? # => nil
Bar = Struct.new(:a, keyword_init: true)
Bar.keyword_init? # => true
Baz = Struct.new(:a, keyword_init: false)
Baz.keyword_init? # => false
//}... -
Struct
# ==(other) -> bool (63100.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
# eql?(other) -> bool (63100.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
# equal?(other) -> bool (63100.0) -
指定された other が self 自身である場合のみ真を返します。 これは Object クラスで定義されたデフォルトの動作で す。
...たデフォルトの動作で
す。
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
@see Struct#eql?, Struct#==... -
Struct
# inspect -> String (63100.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 _ h -> Hash (63100.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 (63100.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 _ s -> String (63100.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) (63082.0) -
構造体の member で指定されたメンバの値を value にして value を返します。
...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =... -
Struct
# each -> Enumerator (63082.0) -
構造体の各メンバに対して繰り返します。
...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =... -
Struct
# each {|value| . . . } -> self (63082.0) -
構造体の各メンバに対して繰り返します。
...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =... -
Struct
# each _ pair -> Enumerator (63082.0) -
構造体のメンバ名(Symbol)と値の組を引数にブロックを繰り返し実行します。
...[ruby]{
Foo = Struct.new(:foo, :bar)
Foo.new('FOO', 'BAR').each_pair {|m, v| p [m,v]}
# => [:foo, "FOO"]
# [:bar, "BAR"]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位... -
Struct
# each _ pair {|member , value| . . . } -> self (63082.0) -
構造体のメンバ名(Symbol)と値の組を引数にブロックを繰り返し実行します。
...[ruby]{
Foo = Struct.new(:foo, :bar)
Foo.new('FOO', 'BAR').each_pair {|m, v| p [m,v]}
# => [:foo, "FOO"]
# [:bar, "BAR"]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位... -
Struct
# filter -> Enumerator (63082.0) -
構造体のメンバの値に対してブロックを評価した値が真であった要素を全て含 む配列を返します。真になる要素がひとつもなかった場合は空の配列を返しま す。
...Lots = Struct.new(:a, :b, :c, :d, :e, :f)
l = Lots.new(11, 22, 33, 44, 55, 66)
l.select {|v| (v % 2).zero? } #=> [22, 44, 66]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下... -
Struct
# filter {|i| . . . } -> [object] (63082.0) -
構造体のメンバの値に対してブロックを評価した値が真であった要素を全て含 む配列を返します。真になる要素がひとつもなかった場合は空の配列を返しま す。
...Lots = Struct.new(:a, :b, :c, :d, :e, :f)
l = Lots.new(11, 22, 33, 44, 55, 66)
l.select {|v| (v % 2).zero? } #=> [22, 44, 66]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下... -
Struct
# hash -> Integer (63082.0) -
self が保持するメンバのハッシュ値を元にして算出した整数を返します。 self が保持するメンバの値が変化すればこのメソッドが返す値も変化します。
...も変化します。
//emlist[例][ruby]{
Dog = Struct.new(:name, :age)
dog = Dog.new("fred", 5)
p dog.hash #=> 7917421
dog.name = "john"
p dog.hash #=> -38913223
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対し......て呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。... -
Struct
# length -> Integer (63082.0) -
構造体のメンバの数を返します。
...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =... -
Struct
# members -> [Symbol] (63082.0) -
構造体のメンバの名前(Symbol)の配列を返します。
...ます。
//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
p Foo.new.members # => [:foo, :bar]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点... -
Struct
# select -> Enumerator (63082.0) -
構造体のメンバの値に対してブロックを評価した値が真であった要素を全て含 む配列を返します。真になる要素がひとつもなかった場合は空の配列を返しま す。
...Lots = Struct.new(:a, :b, :c, :d, :e, :f)
l = Lots.new(11, 22, 33, 44, 55, 66)
l.select {|v| (v % 2).zero? } #=> [22, 44, 66]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下... -
Struct
# select {|i| . . . } -> [object] (63082.0) -
構造体のメンバの値に対してブロックを評価した値が真であった要素を全て含 む配列を返します。真になる要素がひとつもなかった場合は空の配列を返しま す。
...Lots = Struct.new(:a, :b, :c, :d, :e, :f)
l = Lots.new(11, 22, 33, 44, 55, 66)
l.select {|v| (v % 2).zero? } #=> [22, 44, 66]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下... -
Struct
# size -> Integer (63082.0) -
構造体のメンバの数を返します。
...注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe =... -
Struct
# to _ a -> [object] (63082.0) -
構造体のメンバの値を配列にいれて返します。
...= Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_a
# => ["Joe Smith", "123 Maple, Anytown NC", 12345]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.......new は Struct の下位クラスを作成する点に
注意してください。... -
Struct
# values -> [object] (63082.0) -
構造体のメンバの値を配列にいれて返します。
...= Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_a
# => ["Joe Smith", "123 Maple, Anytown NC", 12345]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.......new は Struct の下位クラスを作成する点に
注意してください。... -
Struct
# values _ at(*members) -> [object] (63082.0) -
引数で指定されたメンバの値の配列を返します。
...]{
Foo = Struct.new(:foo, :bar, :baz)
obj = Foo.new('FOO', 'BAR', 'BAZ')
p obj.values_at(0, 1, 2) # => ["FOO", "BAR", "BAZ"]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下... -
Struct
. members -> [Symbol] (63076.0) -
(このメソッドは Struct の下位クラスにのみ定義されています) 構造体のメンバの名前(Symbol)の配列を返します。
...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体のメンバの名前(Symbol)の配列を返します。
//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
p Foo.members # => [:foo, :bar]
//}... -
Struct
# dig(key , . . . ) -> object | nil (63028.0) -
self 以下のネストしたオブジェクトを dig メソッドで再帰的に参照して返し ます。途中のオブジェクトが nil であった場合は nil を返します。
...場合は nil を返します。
@param key キーを任意個指定します。
//emlist[例][ruby]{
klass = Struct.new(:a)
o = klass.new(klass.new({b: [1, 2, 3]}))
o.dig(:a, :a, :b, 0) # => 1
o.dig(:b, 0) # => nil
//}
@see Array#dig, Hash#dig, OpenStruct#dig...