< More tweets

Proposal: A smoosh function where the number of o’s tells how deep to flatten.

smoosh([1,[2,[3,[4]]]]) => [1,2,[3,[4]]]
smooosh([1,[2,[3,[4]]]]) => [1,2,3,[4]]
smoooosh([1,[2,[3,[4]]]]) => [1,2,3,4]

3/15/2018, 5:57:30 PM

Favs: 355

Retweets: 79

JavaScript may have brought up smoosh, but needlessly metaprogrammed, recursive Ruby is its truest home. 😈

class Array
def smoosh
self.flatten(1)
end

def method_missing(m, *_)
if /smo(o+)sh/ =~ m
self.smoosh.send(:"sm#{$1}sh")
end
end
end

3/15/2018, 11:39:31 PM

Favs: 70

Retweets: 11