Ruby’s array#uniq method will evaluate the values of an array, but also evaluate the internals of those values to determine uniqueness when passed a block. >> arr = [{a: 1, b: 2, c: 3}, {a: 3, b: 5, c: 6}] >> arr.uniq => [{:a=>1, :b=>2, :c=>3}, {:a=>1, :b=>5, :c=>6}]   # But if we pass the block comparing object_ids >> arr = [{a: 1, b: 2, c: 3}, {a: 1, b: 5, c: 6}] >> arr.uniq {|obj| obj == obj.object_id} => [{:a=>1, :b=>2, :c=>3}] As the documentation states, “If a block is given, it will use the return value of the block for comparison.”, so we can compare nested key/values object values in addition to entire array values. Thanks to[…]

Ruby #sort method doesn’t do well with nil, so clean nil out of your arrays before attempting to sort. >> arr1 = [nil, "6:1", "1:2", "2:4", "4.3:0.92", "5.0:4", "2.0 to 3"] #=> [nil, "6:1", "1:2", "2:4", "4.3:0.92", "5.0:4", "2.0 to 3"]   >> puts Benchmark.measure { arr1.sort } #=> ArgumentError: comparison of NilClass with String failed from (irb):53:in `sort’   >> arr1 = ["6:1", "1:2", "2:4", "4.3:0.92", "5.0:4", "2.0 to 3"] #=> ["6:1", "1:2", "2:4", "4.3:0.92", "5.0:4", "2.0 to 3"]   >> puts Benchmark.measure { arr1.sort } #=> 0.000000 0.000000 0.000000 ( 0.000012) Use a delete(nil) before sorting. >> arr2 = [nil, "6:1", "1:2", "2:4", "4.3:0.92", "5.0:4", "2.0 to 3"] #=> [nil, "6:1", "1:2", "2:4", "4.3:0.92", "5.0:4", "2.0 to 3"][…]

  >> Calculation.uniq.pluck(:risk_ratio) #=> [nil, "6:1", "1:2", "2:4", "4.3:0.92", "5.0:4", "2.0 to 3"]   >> Calculation.select(:risk_ratio).uniq #=> [#<Calculation risk_ratio: nil>, #<Calculation risk_ratio: "6:1">, #<Calculation risk_ratio: "1:2">, #<Calculation risk_ratio: "2:4">, #<Calculation risk_ratio: "4.3:0.92">, #<Calculation risk_ratio: "5.0:4">, #<Calculation risk_ratio: "2.0 to 3">]   >> Calculation.select(:risk_ratio).uniq.each {|w| puts w.risk_ratio } 6:1 1:2 2:4 4.3:0.92 5.0:4 2.0 to 3 Three different ways to get a unique individual column with slightly different output formats. :)