Please take these recommendations with a grain of salt, most of them will be based on 'personal coding preference' if they are based on an actual error I will be sure to let you know.
def show(wearer = "You")
if wearer == "You"
pronoun = "You"
output = ["You are wearing:"]
else
pronoun = wearer.pronoun
output = ["#{pronoun.capitalize} is wearing:"]
end
wearing = []
@@slots.each do |slot|
line = show_position(slot, wearer)
wearing << line if line
end
if wearing.empty?
if pronoun == "You"
(show_wielding(wearer) << "You are wearing nothing at all.").join("\n")
else
(show_wielding(wearer) << "#{pronoun.capitalize} is wearing nothing at all.").join("\n")
end
else
(show_wielding(wearer) + output + wearing).join("\n")
end
end
recommended change remove the creation of excess object 'pronoun'
def show(wearer = "You")
if wearer == "You"
output = ["You are wearing:"]
else
output = ["#{wearer.pronoun.capitalize} is wearing:"]
end
wearing = []
@@slots.each do |slot|
line = show_position(slot, wearer)
wearing << line if line
end
if wearing.empty?
if wearer == "You"
(show_wielding(wearer) << "You are wearing nothing at all.").join("\n")
else
(show_wielding(wearer) << "#{wearer.pronoun.capitalize} is wearing nothing at all.").join("\n")
end
else
(show_wielding(wearer) + output + wearing).join("\n")
end
end