Last active
August 29, 2015 14:09
-
-
Save ckib16/95a1280b6afa40128cb3 to your computer and use it in GitHub Desktop.
Loop Checkpoint - "Title Case" exercise: Conditional logic not working; elsif condition was never met
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Downcase everything to normalize | |
# | |
require 'pry' | |
class Title | |
attr_accessor :string | |
def initialize(string) | |
@string = string | |
end | |
def fix | |
new_array = [] | |
working_array = string.downcase.split | |
binding.pry | |
working_array.each_with_index do |word, index| | |
if index == 0 | |
new_array << word.capitalize | |
binding.pry | |
elsif word == ("the" || "or" || "and" || "of" || "a") | |
new_array << word.downcase | |
binding.pry | |
else | |
new_array << word.capitalize | |
binding.pry | |
end | |
end | |
new_array.join(" ") | |
binding.pry | |
end | |
end | |
book = Title.new("The Sword and the Stone") | |
book.fix | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment