Issue #16137 has been updated by osyo (manga osyo).


hi.

How about making `# bind_call` an alias of` # === `?

```ruby
class UnboundMethod
  alias_method :===, :bind_call
end
```

see: https://bugs.ruby-lang.org/issues/15955#note-10

Also, you should consider the difference between `when Integer.instance_method(:positive?)` or `when: positive?.to_proc`.

```ruby
case 11
when :positive?.to_proc then :positive
end
```

or

```ruby
case 11
when Integer.instance_method(:positive?) then :positive
end
```

Thank you :)

----------------------------------------
Feature #16137: Add === to UnboundMethod
https://bugs.ruby-lang.org/issues/16137#change-81373

* Author: okuramasafumi (Masafumi OKURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
# 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:
``` ruby
require 'prime'
case 11
when Prime.method(:prime?) then :prime
end
```

However, we cannot do something like this:
```ruby
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:
```ruby
class UnboundMethod
  def ===(other)
    bind(other).call
  end
end
```

# Summary

`===` for `UnboundMethod` can improve readability in case statement.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>