Welcome, Guest. Please login or register.
Kingdoms of Ahln
Pages: [1]
  Print  
Author Topic: Cleanup of equipment.rb  (Read 85 times)
Joseph
Wanderer
*
Posts: 13


View Profile
« on: December 06, 2011, 06:10:01 am »

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. 


Code:
  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'

Code:
  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
Logged
Joseph
Wanderer
*
Posts: 13


View Profile
« Reply #1 on: December 06, 2011, 08:19:20 am »


Code:
@@slots = [

Recommended adds : back, shoulder_right, shoulder_left

Personal preference would be to alphabetize the array, and change left_part to part_left.. aliases could be used for backwards compatibility.. but honestly its not that important.
Logged
Justin
Administrator
Citizen
*****
Posts: 189



View Profile
« Reply #2 on: December 06, 2011, 12:24:24 pm »

Hi Joseph,

I really appreciate your feedback and suggestions.

It would probably be easier to have some of these code conversations on GitHub, that way you could even make the code changes right there and I could merge them in without too much effort.

Thanks again!

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2006-2009, Simple Machines
Terra97 design by Bloc