Issue #10064 has been updated by Koichi Sasada.


just idea.

```ruby
class Symbol
  def ~@
    self.to_proc
  end
end

case 0
when ~:zero?
  p :zero
end
```


----------------------------------------
Feature #10064: &:symbol in when clause
https://bugs.ruby-lang.org/issues/10064#change-47881

* Author: Kenta Murata
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: syntax
* Target version: current: 2.2.0
----------------------------------------
Now we can put Proc objects in a when clause as this code.

~~~
require 'prime'

def test(n)
  print "#{n} is "
  case n
  when :zero?.to_proc
    puts 'zero'
  when :even?.to_proc
    puts 'an even number'
  when :prime?.to_proc
    puts 'a prime number'
  else
    puts 'a non-prime odd number'
  end
end

(1..10).each &method(:test)
~~~

I would like to write it as below:

~~~
require 'prime'

def test(n)
  print "#{n} is "
  case n
  when &:zero?
    puts 'zero'
  when &:even?
    puts 'an even number'
  when &:prime?
    puts 'a prime number'
  else
    puts 'a non-prime odd number'
  end
end

(1..10).each &method(:test)
~~~

How do you think about this new syntax, Matz?




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