Project

General

Profile

Actions

Feature #10064

closed

&:symbol in when clause

Feature #10064: &:symbol in when clause

Added by mrkn (Kenta Murata) over 11 years ago. Updated almost 8 years ago.

Status:
Feedback
Target version:
-
[ruby-core:63835]

Description

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?

Actions

Also available in: PDF Atom