2012-08-15 125 views
2

無我有以下代碼:打印值紅寶石

person1 = { :first => "bob", :last => "perry"} 
person2 = { :first => "fred", :last => "perry"} 
person3 = {:first => "jane", :last =>"perry"} 
family = {:dad => person1, :son => person2, :mum => person3} 

puts (family[:dad][:last],family[:dad][:first]) 

它打印出:

perry 
bob 
nil 

爲什麼還輸出零?

回答

4

因爲你在irb,它打印出最後一次方法運行的返回值,並且puts返回nil。

(或者rails c。)