種類
- インスタンスメソッド (258)
- 特異メソッド (58)
ライブラリ
- ビルトイン (316)
検索結果
先頭5件
-
Struct
. new(*args , keyword _ init: nil) -> Class (23316.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......by]{
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,......t2 = 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:... -
Struct
. new(*args , keyword _ init: nil) {|subclass| block } -> Class (23316.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......by]{
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,......t2 = 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:... -
Struct
. new(*args , keyword _ init: nil) -> Class (23232.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......//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 (......uby]{
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).
# ke... -
Struct
. new(*args , keyword _ init: nil) {|subclass| block } -> Class (23232.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......//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 (......uby]{
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).
# ke... -
Struct
. new(*args) -> Class (23196.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......//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 (......ます。
//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
//}
=== 第一引数が Symbol... -
Struct
. new(*args) {|subclass| block } -> Class (23196.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......//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 (......ます。
//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
//}
=== 第一引数が Symbol... -
Struct
. new(*args , keyword _ init: false) -> Class (23196.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......//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 (......ます。
//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
//}
=== 第一引数が Symbol... -
Struct
. new(*args , keyword _ init: false) {|subclass| block } -> Class (23196.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "......//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 (......ます。
//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
//}
=== 第一引数が Symbol... -
Struct
. new(*args) -> Struct (23151.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
. [](*args) -> Struct (8051.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
# to _ h -> Hash (8031.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 (8031.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
. [](*args) -> Struct (8031.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
# ==(other) -> bool (8025.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 (8025.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
# [](member) -> object (8019.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
# []=(member , value) (8019.0) -
構造体の member で指定されたメンバの値を value にして value を返します。
...の記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith...