I'm trying to reverse words in an array of string variables, but split doesn't seem to be working.
Testing in IRB I get "NoMethodError: private method `split' called for Array", which I'm assuming has something to do with my program quietly doing nothing.
For example, I have:
nameList = ["Joe Blow", "Mary Sue", "Alice Mallory"].
I expect to return:
["Blow Joe", "Sue Mary", "Mallory Alice"].
So I iterate through the array, splitting, reversing and joining. This is where nothing happens:
nameList.each { |x|
x.to_s.split(' ').reverse!.join(' ')
puts x #testing here
}
This outputs:
Joe Blow
Mary Sue
Alice Mallory
I must be missing something extremely simple, as this can't be too difficult.