I have a ruby problem
Here's what i'm trying to do
def iterate1 #define method in given class
@var3 = @var2.split(" ") #split string to array
@var4 = @var3
@var4.each do |i| #for each array item do i
ra = []
i.each_char {|d| ra << counter1(d)} # for each char in i, apply def counter1
@sum = ra.inject(:+)
@sum2 = @sum.inject(:+) #have to do the inject twice to get values
end
@sum2
I know i have over complicated this
Basically the input is a string of letters and values like "14556 this word 398"
I am trying to sum the numbers in each value, seperated by the whitespace like (" ")
When i use the def iterate1 method the block calls the counter1 method just fine, but i can only get the value for the last word or value in the string.
In this case that's 398, which when summed would be 27.
If i include a break i get the first value, which would be 21.
I'm looking to output an array with all of the summed values
Any help would be greatly appreciated