Actions
Feature #16137
openAdd === to UnboundMethod
Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
Description
Abstract¶
UnboundMethod
class should have ===
so that it can be used in case statement.
Background¶
Method
class has ===
method so that we can do something like:
require 'prime'
case 11
when Prime.method(:prime?) then :prime
end
However, we cannot do something like this:
positive = Integer.instance_method(:positive?)
case 11
when positive then :positive
end
Proposal¶
Add ===
method to UnboundMethod
class.
Implementation¶
Minimal implementation in Ruby could be:
class UnboundMethod
def ===(other)
bind(other).call
end
end
Summary¶
===
for UnboundMethod
can improve readability in case statement.
Actions