I have the code -
class Conversion
hash ={'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000}
puts "enter the string"
input = gets.chomp.upcase.split(//)
result = 0
hash.each do | key, value |
case key
when 'M'
result = result + value
when 'D'
result = result + value
when 'C'
result = result + value
when 'L'
result = result + value
when 'X'
result = result + value
when 'V'
result = result + value
when 'I'
result = result + value
end
end
puts result
end
c= Conversion.new
I am giving a string like mxv through command line and converting that into an array and have it as MXV in 'input'. Now I want to iterate over the Hash so I can get the corresponding 'values' of the keys that I have as String in my array. For ex, for MXV , i need values = [1000, 10, 5].
How can I do that?