>> 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.

:)

Leave a Reply

Your email address will not be published. Required fields are marked *