fork download
  1. puts "Enter a number"
  2. n = "0123" # gets.chomp # Inputdoes not work on Ideone, use `gets.chomp` to read input
  3. n.chars.each{|x| puts x == '0' ? "#{x} is a zero digit" :
  4. x.to_i % 2 == 0 ? "#{x} is an even digit" : "#{x} is an odd digit"}
  5. .group_by{|x| [x.to_i % 2 == 0, x == '0']}
  6. .each{|a,b| puts "There are " + ( a.last ? "#{b.length} zeros"
  7. : a.first ? "#{b.length} evens" : "#{b.length} odds" ) + " digits"}
  8.  
Success #stdin #stdout 0.05s 9760KB
stdin
Standard input is empty
stdout
Enter a number
0 is a zero digit
1 is an odd digit
2 is an even digit
3 is an odd digit
There are 1 zeros digits
There are 2 odds digits
There are 1 evens digits