種類
- インスタンスメソッド (377)
- 特異メソッド (83)
ライブラリ
- ビルトイン (421)
-
json
/ add / struct (39)
キーワード
- == (13)
- [] (26)
- []= (13)
-
as
_ json (13) - deconstruct (13)
-
deconstruct
_ keys (13) - dig (13)
- each (26)
-
each
_ pair (26) - eql? (13)
- equal? (13)
- filter (26)
- hash (13)
- inspect (13)
-
json
_ create (13) -
keyword
_ init? (5) - length (13)
- members (26)
- new (39)
- select (26)
- size (13)
-
to
_ a (13) -
to
_ h (26) -
to
_ json (13) -
to
_ s (13) - values (13)
-
values
_ at (13)
検索結果
先頭5件
-
Struct
# ==(other) -> bool (1.0) -
self と other のクラスが同じであり、各メンバが == メソッドで比較して等しい場合に true を返します。そうでない場合に false を返します。
...```ruby title="例"
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** [m:Struct#eql?]... -
Struct
# [](member) -> object (1.0) -
構造体のメンバの値を返します。
...を指定した場合に発生します。
```ruby title="例"
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......# p obj[2] # => in `[]': offset 2 too large for struct(size:2) (IndexError)
```
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に注意して......を指定した場合に発生します。
```ruby title="例"
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......# p obj[2] # => in '[]': offset 2 too large for struct(size:2) (IndexError)
```
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に注意して... -
Struct
# []=(member , value) (1.0) -
構造体の member で指定されたメンバの値を value にして value を返します。
...[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に注意してください。
```ruby title="例"
Customer = Struct.new(:name, :address, :zip)
joe = Cu... -
Struct
# as _ json(*args) -> Hash (1.0) -
{: since="1.9.3"}
...となるハッシュに変換して返します。
[m:Struct#to_json] が内部で使用しています。
ハッシュには、[m:JSON.create_id] をキーとして `self` のクラス名が、`'v'` に各メンバの値の
配列([m:Struct#values] の返り値)が入ります。
- **param** `ar......の
場合に発生します。
```ruby title="例"
require 'json/add/struct'
Person = Struct.new(:name, :age)
hash = Person.new("tanaka", 29).as_json
p hash['json_class'] # => "Person"
p hash['v'] # => ["tanaka", 29]
```
- **SEE** [m:Struct#to_json], [m:Struct.json_create]... -
Struct
# deconstruct -> [object] (1.0) -
{: since="2.7.0"}
...= Struct.new(:name, :address, :zip)
p Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_a
# => ["Joe Smith", "123 Maple, Anytown NC", 12345]
```
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び出す事を想定しています。Struct.......new は Struct の下位クラスを作成する点に注意してください。
- **SEE** [ref:d:spec/pattern_matching#matching_non_primitive_objects]... -
Struct
# deconstruct _ keys(array _ of _ names) -> Hash (1.0) -
{: since="2.7.0"}
...stomer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
h = joe.deconstruct_keys([:zip, :address])
p h # => {:zip=>12345, :address=>"123 Maple, Anytown NC"}
# 引数が nil の場合は全てのメンバを返します。
h = joe.deconstruct_keys(n......:address=>"123 Maple, Anytown NC", :zip=>12345}
```
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に注意してください。
- **SEE** [ref:d:spe......ustomer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
h = joe.deconstruct_keys([:zip, :address])
p h # => {zip: 12345, address: "123 Maple, Anytown NC"}
# 引数が nil の場合は全てのメンバを返します。
h = joe.deconstruct_keys(ni......, address: "123 Maple, Anytown NC", zip: 12345}
```
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に注意してください。
- **SEE** [ref:d:spe... -
Struct
# dig(key , . . . ) -> object | nil (1.0) -
self 以下のネストしたオブジェクトを dig メソッドで再帰的に参照して返します。途中のオブジェクトが nil であった場合は nil を返します。
...す。
- **param** `key` -- キーを任意個指定します。
```ruby title="例"
klass = Struct.new(:a)
o = klass.new(klass.new({b: [1, 2, 3]}))
p o.dig(:a, :a, :b, 0) # => 1
p o.dig(:b, 0) # => nil
```
- **SEE** [m:Array#dig], [m:Hash#dig], [m:OpenStruct#dig]... -
Struct
# each -> Enumerator (1.0) -
構造体の各メンバに対して繰り返します。
...[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に注意してください。
```ruby title="例"
Customer = Struct.new(:name, :address, :zip)
joe = Cu...
