-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sockets - Evelynn #33
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
def is_vowel?(letter) | ||
case letter | ||
when "a", "e", "i", "o", "u" | ||
letter = true | ||
else | ||
letter = false | ||
end | ||
return letter | ||
end | ||
|
||
def run_generator | ||
puts "Please enter your first word for the portmanteau. It must be at least 2 characters long." | ||
word_A = gets.chomp | ||
until word_A.length >= 2 | ||
puts "I'm sorry, this word is invalid. Please enter a word that is at least 2 characters long." | ||
word_A = gets.chomp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Ruby, we typically name variables using all lowercases letters, so this would be |
||
end | ||
word_A_chop = 0 | ||
word_A_last = word_A.length - 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use vertical whitespace (empty lines) to separate different pieces of your code, the same way you would use space to separate paragraphs in English text. Just focusing on the section for the first word, I would probably put a blank line after lines 17, 17, and 33. |
||
word_A.reverse.each_char do |c| | ||
if !is_vowel?(c) && word_A_chop == word_A_last #Ensures words with no vowels will include the full word in portmanteau. | ||
break | ||
elsif is_vowel?(c) | ||
break | ||
end | ||
word_A_chop += 1 | ||
end | ||
if word_A_chop == word_A_last #Ensures words with no vowels will include the full word in portmanteau. | ||
puts "The first half of your word is #{word_A}." | ||
else | ||
word_A = word_A[0...(word_A_last - word_A_chop)] | ||
puts "The first half of your word is #{word_A}." | ||
end | ||
puts "Please enter your second word for the portmanteau." | ||
word_B = gets.chomp | ||
until word_B.length >= 2 | ||
puts "I'm sorry, this word is invalid. Please enter a word that is at least 2 characters long." | ||
word_B = gets.chomp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your code to get the second word is almost exactly the same as the code to get the first word. Could you DRY this up using another method? |
||
end | ||
word_B_chop = 0 | ||
word_B_last = word_B.length - 1 | ||
word_B.each_char do |c| | ||
if is_vowel?(c) && word_B_chop == 0 #Ensures words beginning with vowels will include entire word in portmanteau. | ||
break | ||
elsif is_vowel?(c) | ||
break | ||
elsif !is_vowel?(c) && word_B_chop == word_B_last | ||
word_B_chop = 0 #Reset to 0 so that all-consonant words will include entire word in portmanteau. | ||
break | ||
else | ||
word_B_chop += 1 | ||
end | ||
end | ||
word_B = word_B[word_B_chop..word_B_last] | ||
puts "The second half of your word is #{word_B}." | ||
puts "\nYour portmanteau is #{word_A + word_B}." | ||
end | ||
|
||
run_generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably not store the
true
orfalse
value inletter
, because we would expectletter
to be a one-character string. Instead you could create a new variable (maybevowel
), or just return from inside thecase
statement.