I'm trying to iterate through an array, @chem_species = ["H2", "S", "O4"]
and multiply a constant times the amount of constants present: H = 1.01 * 2, S = 32.1 * 1
and so on. The constants are of course defined within the class, before the instance method.
The code I've constructed to do this does not function:
def fw
x = @chem_species.map { |chem| chem.scan(/[A-Z]/)}
y = @chem_species.map { |chem| chem.scan({/\d+/)}
@mm = x[0] * y[0]
end
yields -> TypeError: can't convert Array into Integer
Any suggestions on how to better code this? Thank you for your insight in advance.