hash inject : inject « Hash « Ruby






hash inject


require 'time'
click_counts = {}

1.upto(30) { |i| click_counts[Time.parse("2006-09-#{i}")] = 400 + rand(700) }
p click_counts

low_click_days_hash = click_counts.inject({}) do |h, kv|
  k, v = kv
  h[k] = v if v < 450
  h
end

 








Related examples in the same category

1.inject with regular expression