Skip to content

Instantly share code, notes, and snippets.

@ckib16
Last active August 29, 2015 14:09
Show Gist options
  • Save ckib16/95a1280b6afa40128cb3 to your computer and use it in GitHub Desktop.
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
# 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