Skip to content

Instantly share code, notes, and snippets.

@albertico
Last active August 29, 2015 14:10
Show Gist options
  • Save albertico/ca05f760a07cd14263b6 to your computer and use it in GitHub Desktop.
Save albertico/ca05f760a07cd14263b6 to your computer and use it in GitHub Desktop.
How to reverse a string and replace the vowels with their corresponding ASCII decimal value (using Ruby)

How to reverse a string and replace the vowels with their corresponding ASCII decimal value (using Ruby)

For the purpose of this example, the Interactive Ruby Shell (IRB) will be used.

Start the IRB by executing the irb command from your terminal:

% > irb

Then, execute the following code:

"HERE_GOES_YOUR_STRING".reverse!.gsub!(/[aeiou]/) { |m| m.ord.to_s }

The following output will be returned:

=> "gn105rts r117111y s101111g 101r101h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment