Array
doesn't have sort_by
; Enumerable
has it. How does this work?
%w[aa aaaa aaa].sort_by{|item| item.length} #=> ['aa','aaa','aaaa']
Doesn't this have to throw an error like undefined method sort_by
? What is the relationship between Array
and Enumerable
?
The Array
class includes the Enumerable
module. You can see that in the documentation on the left under "Included Modules".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With