Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3.2でSetが組み込みライブラリになったことに対応 #2769

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions refm/api/src/LIBRARIES
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ scanf
#@end
sdbm
securerandom
#@until 3.2
set
#@end
#@until 2.7.0
shell
shell/error
Expand Down
3 changes: 3 additions & 0 deletions refm/api/src/_builtin.rd
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ require を書かなくても使うことができます。
#@include(_builtin/RuntimeError)
#@include(_builtin/ScriptError)
#@include(_builtin/SecurityError)
#@since 3.2
#@include(_builtin/Set)
#@end
#@include(_builtin/Signal)
#@include(_builtin/SignalException)
#@since 2.3.0
Expand Down
35 changes: 35 additions & 0 deletions refm/api/src/_builtin/Enumerable
Original file line number Diff line number Diff line change
Expand Up @@ -1645,3 +1645,38 @@ to_enum(:with_nils).compact # => [1, 2, 3]

@see [[m:Array#compact]]
#@end

#@since 3.2
--- to_set(klass = Set, *args) -> Set
--- to_set(klass = Set, *args) {|o| ... } -> Set

Enumerable オブジェクトの要素から、新しい集合オブジェクトを作ります。

引数 klass を与えた場合、Set クラスの代わりに、指定した集合クラスの
インスタンスを作ります。

この引数を指定することで、ユーザ定義の集合クラスのインスタンスを作ることができます
(ここでいう集合クラスとは、Setとメソッド/クラスメソッドで互換性のあるクラスです。
Ruby 2.7 以前は SortedSet が定義されていました)。

引数 args およびブロックは、集合オブジェクトを生成するための new
メソッドに渡されます。


@param klass 生成する集合クラスを指定します。
@param args 集合クラスのオブジェクト初期化メソッドに渡す引数を指定します。
@param block 集合クラスのオブジェクト初期化メソッドに渡すブロックを指定します。
@return 生成された集合オブジェクトを返します。

#@samplecode
p [30, 10, 20].to_set
#=> #<Set: {30, 10, 20}>
MySet = Class.new(Set)
p [30, 10, 20].to_set(MySet)
#=> #<MySet: {10, 20, 30}>
p [30, 10, 20].to_set {|num| num / 10}
#=> #<Set: {3, 1, 2}>
#@end

@see [[m:Set.new]]
#@end
Loading