M
Mischa Fierer
Hello,
I've been going through the enumerable/enumerator methods that I'm
unfamiliar with and came across each_cons. Apart from a post by a guy
who wasn't sure where it was even defined, I have only come across one
use of it in the wild:
(From Prawn)
def polygon(*points)
move_to points[0]
(points << points[0]).each_cons(2) do |p1,p2|
line_to(*p2)
end
end
Does anyone have any ideas on other cases where each_cons would be
useful? Or perhaps insight into why it's in Ruby?
Best,
M
I've been going through the enumerable/enumerator methods that I'm
unfamiliar with and came across each_cons. Apart from a post by a guy
who wasn't sure where it was even defined, I have only come across one
use of it in the wild:
(From Prawn)
def polygon(*points)
move_to points[0]
(points << points[0]).each_cons(2) do |p1,p2|
line_to(*p2)
end
end
Does anyone have any ideas on other cases where each_cons would be
useful? Or perhaps insight into why it's in Ruby?
Best,
M