Given following Ruby statements:
(Read input and store each word in array removing spaces between words etc)
input = gets.chomp inArr = [] input.strip.each (' ') { |w| inArr.push w } inArr.delete_if {|ele| ele == ' '} inArr.each {|w| w.strip!}
I was wondering if anyone can suggest a way to optimize this code, maybe via chaining or removing some unneeded statements, because i have a feeling this can be done in much less code, but since I’m new to Ruby its hard for me to see how 🙂
Thank,
RM
gets.splitshould get you what you want