method
group_by
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
group_by()
public
Returns a hash, which keys are evaluated result from the block, and values are arrays of elements in enum corresponding to the key.
If no block is given, an enumerator is returned instead.
(1..6).group_by {|i| i%3} #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
Register or
log in
to add new notes.
sselvamani22 -
February 12, 2016
![Default_avatar_30](https://www.gravatar.com/avatar/ae823fe7f85ddc410add2511eaaae546?size=30&default=http://apidock.com/images/default_avatar_30.png)
0 thanks
group on hash
‘
def group_by_hash hash, value hash.group_by do |k,v| v > value ? "Big" : "Small" end end marks = {"Chair" => 30, "Table" => 40, "Bed" => 60, "stool" => 20} group_by_hash(marks, 30)