On Mar 7, 2014, at 10:12 PM, tamouse pontiki [email protected]
wrote:
wouldn’t mind writing it down, but never seem to get around to it. If
the older ruby bloggers aren’t anymore, maybe more of us should take
it up? (I’m probably age-wise older than many of them, but still
learning lots)
I should start writing something once a week about Ruby. I love the
language and community, and I enjoy using it. As for older, I suspect I
too am on the “to grave” side of the “from cradle to grave” curve.
This week I used Array#product at work, and that saved me a lot of time.
I’ll blog about that at Stok Footage | Believe what you want, it doesn’t mean you’re right
Hope this helps,
Mike
[1] pry(main)> ? Array#product
From: array.c (C Method):
Owner: Array
Visibility: public
Signature: product(*arg1)
Number of lines: 14
Returns an array of all combinations of elements from all arrays.
The length of the returned array is the product of the length of self
and
the argument arrays.
If given a block, #product will yield all combinations and return self
instead.
[1,2,3].product([4,5]) #=> [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]]
[1,2].product([1,2]) #=> [[1,1],[1,2],[2,1],[2,2]]
[1,2].product([3,4],[5,6]) #=> [[1,3,5],[1,3,6],[1,4,5],[1,4,6],
# [2,3,5],[2,3,6],[2,4,5],[2,4,6]]
[1,2].product() #=> [[1],[2]]
[1,2].product([]) #=> []
–
Mike S. [email protected]
http://www.stok.ca/~mike/
The “`Stok’ disclaimers” apply.