Thanks for the tip and looking over my codes, helpful. 


________________________________
 From: clearf <notifications@github.com>
To: clearf/WDI_Homework_Week1_Day5_Stock_Exchange <WDI_Homework_Week1_Day5_Stock_Exchange@noreply.github.com> 
Cc: bigfattunafish <thomas.whyyou@ymail.com> 
Sent: Tuesday, June 25, 2013 4:14 PM
Subject: Re: [WDI_Homework_Week1_Day5_Stock_Exchange] Week1 Day5 Stock Exchange homework submission (#9)
 


In lib/portfolio.rb:
> +class Portfolio
> +  attr_accessor :port_name, :inv_count, :portfolio_bal, :composition
> +
> +  def initialize (port_name, inv_count = 0, portfolio_bal = 0)
> +    @port_name = port_name
> +    @inv_count = inv_count
> +    @portfolio_bal = portfolio_bal
> +    @composition = {} # Hash to contain: ticker and # of shares
> +  end
> +
> +  def add_stock(ticker, shares_bought)
> +    temp_array = []
> +    self.composition.each do |stock, shares|
> +      temp_array << stock.to_s
> +    end
> +    if temp_array.include?(ticker) 
Oh, I see. This isn't the right way to do this. To check if a key exists in a hash, do: 
hash[key].nil? # to tell if it is not defined.  Or, 
hash[key] # If the key is not defined, this will generally nil. So you can do things like this. 
you can also just do 
if hash.has_key?(key)  #Note that these are (), because this is a function.  # This executes if the key IS defined.  puts "That key is defined"
end 
—
Reply to this email directly or view it on GitHub.