Hi all,
Could someone explain the ‘flow’ of how the eg below is processed?
My limited understanding is that the left hand side is the receiver and
the right hand side the method being passed to the receiver?
What I don’t understand is where the block comes into the equation for
something like the following:
values = anagrams.values.sort do |a, b|
b.length <=> a.length
end
The block changes how the sort method sorts? ie it sorts by length
rather
than alphabetically? So it overrides the default meaning of <=>??
We get the values of the anagram hash by the ‘values’ method?
We then do:
.sort do |a, b| b.length <=> a.length end
ie this whole line acts on the values array??
not a 2 step process of 1. the sort method then 2. the block applied in
some way?
To illustrate what I’m failing dismally to explain here:
Using () for grouping, is it processed as A or B?
A
values = anagrams.values.(sort do |a, b| b.length <=> a.length)
end
B
values = anagrams.values.(sort) (do |a, b| b.length <=> a.length)
end
thanks,