ãããããã£ãã®ã§ã以ä¸ã®ã¡ã½ãããæ¸ãããã©ãå®ã¯çµã¿è¾¼ã¿ã§åºæ¥ããããããªã説ã
class Hash def summation(*keys) keys.inject(0) do |sum, key| sum += self[key] end end end
以ä¸ã®ããã«ä½¿ã
h = { :a => 1, :b => 2, :c => 100 } p h.summation(:a, :b) #=> 3
使ããªãäºããªãã