Reverse the words, move the vowels and downcase everything I'm brand new to Ruby.
The function takes in a string of any number of words, and reverses the order of the words. Also, for each word, it takes the vowels and moves it to the end of the word. It also downcases everything. Thus, Hello World! would become wrld!o hlleo.
I am trying to use some Ruby features, hence why it is a one-liner so to speak. Basically I am just looking for style suggestions. Is it appropriate to do such a thing in this manner (one line?). I'm sure there are functions that could accomplish the task quicker, so I am open to those suggestions too, since my code is very long and convoluted. Also I should mention I wanted to write this with only base Ruby, no extra packages/gems.
Someone suggested Rubocop and the Style Guide so I will check those out.
  def funky_words(s)
    s.strip.gsub(/\s+/, &quot; &quot;).split(&quot; &quot;).reverse.instance_eval{map{|elt| elt.gsub(/([aeiou])/i,&quot;&quot;)}}.
    zip(s.strip.split(&quot; &quot;).reverse.map{|elt| elt.scan(/([aeiou])/i).flatten}.instance_eval{map{|elt| elt.join}}).
    map(&amp;:join).join(&quot; &quot;).downcase
    #first &quot;line&quot; reverses word order removes vowels, second &quot;line&quot; captures vowels, last &quot;line&quot; joins vowels and all words
  end
One-liners are good fun, but the world doesn't really need more of them. That said, they don't have to be so unreadable. What will your future brain say a year from now if you have to maintain that function?
Here's an approach illustrating a scalable technique to make even long &quot;one-liners&quot; readable by (1) using lines generously, (2) indenting code in the manner of a pretty-printed data structure to convey the logic's hierarchy (code is data, after all), and (3) including comments to assist the reader with the logic and intent.
def funky_words(s)
  (
    # Split into words.
    s
    .split
    .reverse_each
    .map { |word|
      # Within each word, push vowels to the end, while preserving
      # original order within consonants and vowels.
      word
      .each_char
      .sort_by.with_index { |c, i| &quot;aeiouAEIOU&quot;.include?(c) ? [1, i] : [0, i] }
      .join
    }
    # Rejoin the new words.
    .join(&quot; &quot;)
  )
end