# Getting unexpected "end"

**URL:** <https://www.ruby-forum.com/t/getting-unexpected-end/260641>\
**Category:** Rails I18n\
**Created:** [December 17, 2020, 11:00pm UTC](https://www.ruby-forum.com/t/getting-unexpected-end/260641 "2020-12-17T23:00:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonybotony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@sonybotony](https://www.ruby-forum.com/u/sonybotony)\
**Post date:** [December 17, 2020, 11:00pm UTC](https://www.ruby-forum.com/t/getting-unexpected-end/260641/1 "2020-12-17T23:00:13Z")

</div>

Where am i putting the extra “end?”

def abbreviate\_sentence(sent)  
words = sent.split(" “)  
new\_words = []  
vowels = “aeiou”  
words.each do |word|  
if word.length \< 4  
new\_words \<\< word  
end  
words.each do |word|  
word.each do |char|  
if !vowels.include?(char)  
new\_words += char  
end  
end  
return new\_words.join(” ")  
end

---

<div class="post-metadata">

**Author:** ![pcl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pcl](https://www.ruby-forum.com/u/pcl)\
**Post date:** [December 18, 2020, 1:15am UTC](https://www.ruby-forum.com/t/getting-unexpected-end/260641/2 "2020-12-18T01:15:03Z")

</div>

> Where am i putting the extra “end?”

If anything, there are two too few ‘ends’.

Maybe you need to end the two ‘do’ expressions? e.g. see commented ‘ends’:

```auto
def abbreviate_sentence(sent)
  words = sent.split(" ")
  new_words = []
  vowels = "aeiou"
  words.each do |word|
    if word.length < 4
      new_words << word
    end
  end # added
  words.each do |word|
    word.each do |char|
      if !vowels.include?(char)
        new_words += char
      end
    end
  end # added
  return new_words.join(" ")
end

```

BTW, I have no idea what you want the function to do. If you describe it, I can help you put the ‘ends’ in the right place. (You have two lots of `words.each do |word| ...`)

---

<div class="post-metadata">

**Author:** ![sonybotony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@sonybotony](https://www.ruby-forum.com/u/sonybotony)\
**Post date:** [December 18, 2020, 1:34am UTC](https://www.ruby-forum.com/t/getting-unexpected-end/260641/3 "2020-12-18T01:34:08Z")

</div>

Problem:  
Write a method `abbreviate_sentence` that takes in a sentence string and returns a new sentence where every word longer than 4 characters has all of it’s vowels removed.puts

puts abbreviate\_sentence(“follow the yellow brick road”) # =\> “fllw the yllw brck road”  
puts abbreviate\_sentence(“what a wonderful life”) # =\> “what a wndrfl life”

The answer in the tutorial calls for a helper method. Where i make a method that abbreviates the word. I wanted to cut that step out.
