L
Logan Capaldo
Just a few minutes ago I was playing with irb as I am wont to do, and
typed this:
('a'..'z').join(' ')
Lo and behold it protested at me with a NoMethodError. I said to my
self, self there is no reason that has to be Array only functionality.
Why isn't it in Enumerable? So I said:
module Enumerable
def join(sep =3D '')
inject do |a, b|
"#{a}#{sep}#{b}"
end
end
end
And then I said ('a'..'z').join(' ') and got:
=3D> "a b c d e f g h i j k l m n o p q r s t u v w x y z"
#inject has to be the most dangerously effective method ever. But I digress=
:
Why is join, and perhaps even pack in Array and not in Enumerable?
typed this:
('a'..'z').join(' ')
Lo and behold it protested at me with a NoMethodError. I said to my
self, self there is no reason that has to be Array only functionality.
Why isn't it in Enumerable? So I said:
module Enumerable
def join(sep =3D '')
inject do |a, b|
"#{a}#{sep}#{b}"
end
end
end
And then I said ('a'..'z').join(' ') and got:
=3D> "a b c d e f g h i j k l m n o p q r s t u v w x y z"
#inject has to be the most dangerously effective method ever. But I digress=
:
Why is join, and perhaps even pack in Array and not in Enumerable?