title: Ruby group by range, array of numbers?
body: <p>I'm trying to create a histogram from an array of numbers in the range <code>[0,1]</code>.</p>
  
  <p>Is there a way to use <code>group_by</code> to separate the array into N groups/bins by numeric interval (or some other fun Ruby one-liner)?</p>
  
  <p>This is my current, boring, solution:</p>
  
  <pre><code># values == array containing floating point numbers in the range [0,1]
  
  n = 10
  
  # EDITED from Array.new(n, 0) to Array.new(n, []), thanks emaillenin!
  histogram = Array.new(n, [])
  values.each do |val|
    histogram[(val * n).ceil - 1].push(val)
  end
  </code></pre>