Replacing the vowels of a string with the letter "X" This code replaces every vowel of the string with "X":

def vowel_censor(sentence)
    vowels = "aeiou".chars
    result = []
    sentence.chars.each do |charachter|
      if vowels.include?(charachter)
        result &lt;&lt; "X"
      else
        result &lt;&lt; charachter
      end
    end
    result.join("")
end


puts "---------Vowel Censor----------"
puts vowel_censor("Let's order a pizza") == "LXt's XrdXr X pXzzX"
puts vowel_censor("Nitwit, blubber, oddment, tweak") == "NXtwXt, blXbbXr, XddmXnt, twXXk"
puts vowel_censor("Supercalifragilisticexpialidocious") == "SXpXrcXlXfrXgXlXstXcXxpXXlXdXcXXXs"
Look into regular expressions, which Ruby is very good at:

def vowel_censor(string)
  string.gsub(/[aeiou]/i, "X") # case-insensitive
end


Or, even easier, more low-level and more efficient, use String#tr:

def vowel_censor(string)
  string.tr("aeiou", "X") # lowercase only; use "aeiouAEIOU" to handle both upper- and lowercase
end


For your current code:


The Ruby convention is 2 spaces of indentation. Not 4 spaces, not tabs
Your code doesn't handle uppercase vowels
join doesn't need an argument in this case
charachter is misspelt
Don't create a variable (result in this case) and modify it from inside a block unless you really, really have to. Do something like this instead:

sentence.chars.reduce([]) do |result, char| # reduce is also aliased as #inject
  result &lt;&lt; vowels.include?(char) ? "X" : char
end.join


or (building a string instead of an array)

sentence.chars.reduce("") do |result, char|
  result += vowels.include?(char) ? "X" : char
end


or (using a method similar to reduce)

sentence.chars.each_with_object([]) do |result, char|
  result &lt;&lt; vowels.include?(char) ? "X" : char
end.join