class Addnumbers attr_reader :s def initialize(s: "") @s = s end def datainput begin @s = gets.chomp rescue end end def total_numbers(str) str = str.split("") str.each_with_index do |c, i| str[i] = (c =~ /[0-9]/)? c.to_i : 0 end str.inject(:+) end def dataoutput puts total_numbers(@s) end def run datainput dataoutput end end if $0 == __FILE__ Addnumbers.new.run end