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

Object#=== の修正 #2839

Merged
merged 2 commits into from
Oct 26, 2023
Merged
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
32 changes: 17 additions & 15 deletions refm/api/src/_builtin/Object
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,12 @@ p :ruby.hash #=> 3979895509189707770

--- ===(other) -> bool

メソッド [[m:Object#==]] の別名です。
case 式で使用されます。このメソッドは case 式での振る舞いを考慮して、
case 式で使用されるメソッドです。[[ref:d:spec/control#case]] も参照してください。

このメソッドは case 式での振る舞いを考慮して、
各クラスの性質に合わせて再定義すべきです。

一般的に所属性のチェックを実現するため適宜再定義されます
デフォルトでは内部で [[m:Object#==]] を呼び出します

when 節の式をレシーバーとして === を呼び出すことに注意してください。

Expand All @@ -708,19 +709,20 @@ when 節の式をレシーバーとして === を呼び出すことに注意し

#@samplecode
age = 12
# (0..2).===(12), (3..6).===(12), ... が実行される
result =
case age
when 0 .. 2
"baby"
when 3 .. 6
"little child"
when 7 .. 12
"child"
when 13 .. 18
"youth"
else
"adult"
end
case age
when 0 .. 2
"baby"
when 3 .. 6
"little child"
when 7 .. 12
"child"
when 13 .. 18
"youth"
else
"adult"
end

puts result #=> "child"

Expand Down