ライブラリ
- ビルトイン (347)
- csv (88)
- fiddle (22)
- forwardable (22)
- monitor (33)
-
net
/ http (22) - optparse (33)
- ostruct (22)
- pstore (66)
- psych (11)
- rake (22)
-
rake
/ packagetask (22) -
rexml
/ document (55) - shell (12)
-
shell
/ command-processor (12) -
shell
/ filter (12) - stringio (11)
- strscan (11)
- thread (4)
- thwait (60)
-
webrick
/ httputils (11) - win32ole (66)
クラス
- Array (16)
-
CSV
:: Row (44) -
CSV
:: Table (44) - Data (8)
- Enumerator (22)
-
Fiddle
:: Handle (22) - Hash (55)
- Method (40)
- Module (11)
-
ObjectSpace
:: WeakMap (11) - OpenStruct (22)
- OptionParser (33)
- PStore (55)
-
Psych
:: Nodes :: Document (11) -
REXML
:: Attributes (33) -
REXML
:: Elements (22) -
Rake
:: FileList (11) -
Rake
:: PackageTask (22) -
Rake
:: TaskArguments (11) - Range (12)
- Regexp (22)
- Shell (12)
-
Shell
:: CommandProcessor (12) -
Shell
:: Filter (12) - StringIO (11)
- StringScanner (11)
- Struct (66)
- Thread (44)
- ThreadsWait (60)
-
WEBrick
:: HTTPUtils :: FormData (11) - WIN32OLE (22)
-
WIN32OLE
_ TYPE (11) -
WIN32OLE
_ VARIABLE (11) -
WIN32OLE
_ VARIANT (22)
モジュール
- Forwardable (22)
- MonitorMixin (11)
-
Net
:: HTTPHeader (22)
オブジェクト
- ENV (22)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - === (7)
- ConditionVariable (11)
- Marshal フォーマット (11)
- Monitor (11)
- MonitorMixin (11)
-
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 1 . 0 (3) - PStore (11)
- Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (11)
- SizedQueue (11)
- []= (132)
- abort (11)
-
all
_ waits (18) - call (22)
- commit (11)
-
def
_ delegator (11) -
def
_ instance _ delegator (11) -
default
_ argv= (11) -
default
_ event _ sources (11) - delete (11)
- empty? (6)
- entries (6)
- fetch (11)
- field (11)
- finished? (6)
- join (28)
-
join
_ nowait (6) - match (22)
-
mon
_ enter (11) -
next
_ values (11) -
next
_ wait (6) -
ole
_ type _ detail (11) - optparse (11)
- pack (16)
-
package
_ files (11) -
package
_ files= (11) -
peek
_ values (11) - prefixes (11)
-
rb
_ ary _ new (11) - readlines (11)
-
rexml
/ parsers / pullparser (11) -
rexml
/ parsers / sax2parser (11) -
rexml
/ parsers / streamparser (11) - rss (11)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 3 feature (11) -
ruby 1
. 9 feature (11) - store (11)
- summarize (22)
- sym (11)
- test (18)
- threads (6)
-
to
_ a (6) - transaction (11)
- tsort (11)
-
undef
_ method (11) - value (11)
-
webrick
/ cgi (11) - クラス/メソッドの定義 (11)
- 演算子式 (11)
検索結果
先頭5件
-
NEWS for Ruby 2
. 7 . 0 (26054.0) -
NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 2.7.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス......て導入されました。 14912
//emlist[][ruby]{
case [0, [1, 2, 3]]
in [a, [b, *c]]
p a #=> 0
p b #=> 1
p c #=> [2, 3]
end
//}
//emlist[][ruby]{
case {a: 0, b: 1}
in {a: 0, x: 1}
:unreachable
in {a: 0, b: var}
p var #=> 1
end
//}
//emlist[][ruby]{
case -1
in 0 then :unreachable
in 1......name: "Alice", children: [{name: "Charlie", age: age}]}
#=> NoMatchingPatternError
//}
* 詳細は https://speakerdeck.com/k_tsj/pattern-matching-new-feature-in-ruby-2-dot-7 のスライドを参照してください。
* スライドは少し古い内容になっていることに注意して... -
NEWS for Ruby 3
. 1 . 0 (26048.0) -
NEWS for Ruby 3.1.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 3.1.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス......mlist[][ruby]{
foo[0] = bar
//}
* 次の評価順序になります。
//emlist{
1. `foo`
2. `bar`
3. `[]=` called on the result of `foo`
//}
* Ruby 3.1.0より前は、多重代入の評価順序が上記のようではありませんでした。このコードでは、
//emlist[][rub......`foo`
4. `[]=` called on the result of `foo`
5. `bar`
6. `baz=` called on the result of `bar`
//}
* Ruby 3.1.0から単一代入と評価順序が一致するようになり、左が右より先に評価されます。
//emlist{
1. `foo`
2. `bar`
3. `a`
4. `b`
5. `[]=` called on... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (24398.0) -
1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))
...スのスーパークラスは同じなのだそうです
((<ruby-bugs-ja:324>))。さあっぱりわかりません(^^;;
class << Object.new
class << self.superclass
p [self.id, self]
end
class << self
p [self.superclass.id, self.supe......けるのに疲れたらしい
^^;;)
: ((<Proc/Proc.new>)) [change]
: ((<組み込み関数/lambda>)) [change]
: ((<組み込み関数/proc>)) [change]
以下のように変更されました。((<ruby-dev:20358>))
* Proc.new およびブロック引数で与えられる Proc は......を返すことができます。
: 多重代入 [change]
多重代入の規則を見直しました。
# # derived from sample/test.rb
# a = *[]; p a # special case
# def f; yield; end; f {|a| p a} # add (warning)
# def r; return; end; a = r(); p a
#... -
ruby 1
. 9 feature (23504.0) -
ruby 1.9 feature ruby version 1.9.0 は開発版です。 以下にあげる機能は将来削除されたり互換性のない仕様変更がなされるかもしれません。 1.9.1 以降は安定版です。 バグ修正がメインになります。
...* [regexp]: 正規表現の機能拡張
* [marshal]: Marshal ファイルのフォーマット変更
* レベル
* [bug]: バグ修正
* [new]: 追加されたクラス/メソッドなど
* [compat]: 変更されたクラス/メソッドなど(互換性のある変更) (only backward-......: UNIXserver
削除
=== 2006-06-11
: __callee__ [new]
: __method__ [new]
((<URL:http://www.dm4lab.to/~usa/ruby/d/200606a.html#id20060610_P1_7>))
: Symbol#to_proc
=== 2006-06-10
* 新機能
: BasicObject が導入されました [new]
: local という visibility および Module#loca......1文字の String を返すようになりました
: sprintf の %c が 1文字の String を受け付けるようになりました
: String#[]= が右辺の整数を受け付けなくなりました
: String#chr という先頭の1文字を返すメソッドが追加されました
: I... -
ruby 1
. 8 . 3 feature (23378.0) -
ruby 1.8.3 feature *((<ruby 1.8 feature>)) *((<ruby 1.8.2 feature>))
...* [ruby]: ruby インタプリタの変更
* [api]: 拡張ライブラリ API
* [lib]: ライブラリ
* レベル
* [bug]: バグ修正
* [new]: 追加されたクラス/メソッドなど
* [compat]: 変更されたクラス/メソッドなど
* 互換性のある変更
* on......ry_secure [lib] [new]
: FileUtils.remove_entry [lib] [new]
: FileUtils.chmod_R [lib] [new]
: FileUtils.chown [lib] [new]
: FileUtils.chown_R [lib] [new]
: FileUtils.commands [lib] [new]
: FileUtils.options [lib] [new]
: FileUtils.ha......SAFE
Hoge.new.foo
$ ruby-1.8.2 mthd_taint.rb
0
"safe level: 0"
$ ruby-1.8.3 mthd_taint.rb
0
mthd_taint.rb:11:in `foo': calling insecure method: foo (SecurityError)
from mthd_taint.rb:11
=== 2005-09-09
: String#* [ruby] [compat]
: String#[] [ruby] [comp... -
ruby 1
. 6 feature (23318.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...00019>))
: 2002-09-11: Queue#((<Queue/pop>))
Queue#pop に競合状態の問題がありました ((<ruby-dev:17223>))
: 2002-09-11: SizedQueue.new
引数に 0 以下を受けつけるバグが修正されました。
: 2002-09-05: ((<リテラル/式展開>))
stable snapshot で、一......フォルト値 (((<Hash/default>))) も == で等しい
ときに等しいとみなされるようになりました。
p Hash.new("foo") == Hash.new("bar")
=> ruby 1.6.7 (2002-03-01) [i586-linux]
true
=> ruby 1.6.7 (2002-08-21) [i586-linux]
false......範囲外の文字列を指定したときに例外を返す場合がありましたが、常に nil
を返すようになりました。(String#[]やString#slice と同じ結果を返すと
いうことです)
p "foo".slice!("bar") # <- 以前からこちらは nil を返してい... -
Struct
. new(*args , keyword _ init: nil) -> Class (18315.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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, z: 3......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: 1,... -
Struct
. new(*args , keyword _ init: nil) {|subclass| block } -> Class (18315.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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, z: 3......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: 1,... -
Psych
:: Nodes :: Document . new(version=[] , tag _ directives=[] , implicit=false) -> Psych :: Nodes :: Document (18307.0) -
Document オブジェクトを生成します。
...YAML 1.1 のドキュメントで、
tag directive を1つ持ち、 implicit にドキュメントが開始
している Document オブジェクトを生成しています。
Psych::Nodes::Document.new(
[1,1],
tenderlovemaking.com,2009:",
true)
@see Psych::Handler#start_document... -
Data
. [](**kwargs) -> Data (18216.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2
p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}
new に渡す引数の数がメンバの数より多い場合は new でエラーになります。
new に渡す引数の数がメンバの数より少ない場合は new では......のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ......alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown... -
Data
. [](*args) -> Data (18216.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2
p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}
new に渡す引数の数がメンバの数より多い場合は new でエラーになります。
new に渡す引数の数がメンバの数より少ない場合は new では......のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ......alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown... -
Data
. new(**kwargs) -> Data (18216.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2
p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}
new に渡す引数の数がメンバの数より多い場合は new でエラーになります。
new に渡す引数の数がメンバの数より少ない場合は new では......のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ......alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown... -
Data
. new(*args) -> Data (18216.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...= Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2
p2 = Point.new(x: 3, y: 4)
p p2.x # => 3
p p2.y # => 4
//}
new に渡す引数の数がメンバの数より多い場合は new でエラーになります。
new に渡す引数の数がメンバの数より少ない場合は new では......のケースでもエラーが発生していますが、
Point.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してくださ......alize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown... -
Struct
. new(*args) -> Class (18195.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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 (unkn......ラーになります。
//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
//}
=== 第一... -
Struct
. new(*args) {|subclass| block } -> Class (18195.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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 (unkn......ラーになります。
//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
//}
=== 第一... -
Struct
. new(*args , keyword _ init: false) -> Class (18195.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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 (unkn......ラーになります。
//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
//}
=== 第一... -
Struct
. new(*args , keyword _ init: false) {|subclass| block } -> Class (18195.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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 (unkn......ラーになります。
//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
//}
=== 第一... -
Struct
. new(*args , keyword _ init: nil) -> Class (18195.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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 (unkn......ラーになります。
//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
//}
=== 第一... -
Struct
. new(*args , keyword _ init: nil) {|subclass| block } -> Class (18195.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
...では構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合......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 (unkn......ラーになります。
//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
//}
=== 第一... -
Struct
. [](*args) -> Struct (18150.0) -
(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。
...なければ nil です。
@return 構造体クラスのインスタンス。
@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。
//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}... -
Struct
. new(*args) -> Struct (18150.0) -
(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。
...なければ nil です。
@return 構造体クラスのインスタンス。
@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。
//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}... -
Hash
. new(ifnone = nil) -> Hash (18135.0) -
空の新しいハッシュを生成します。ifnone はキーに対 応する値が存在しない時のデフォルト値です。設定したデフォルト値はHash#defaultで参照できます。
...略した Hash.new は {} と同じです。
デフォルト値として、毎回同一のオブジェクトifnoneを返します。
それにより、一箇所のデフォルト値の変更が他の値のデフォルト値にも影響します。
//emlist[][ruby]{
h = Hash.new([])
h[0] << 0
h[1]......uby]{
h = Hash.new([])
p h[1] #=> []
p h[1].object_id #=> 6127150
p h[1] << "bar" #=> ["bar"]
p h[1] #=> ["bar"]
p h[2] #=> ["bar"]
p h[2].object_id #=> 6127150
p h #=> {}
h = Hash.new([].freeze)
h[0] +...