Ruby program to split number into digits



Write a Ruby program to split number into digits

class NumberToDigits
  def printNumberToDigit
    print "Enter the number "
    num = gets.chomp
    print "Digits are: "
    num.split("").each do |n|
      print n+ " "
    end
  end
end

p = NumberToDigit.new 
p.printNumberToDigits

Output:


  
Enter the number  589
Digits are: 5 8 9