-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The three rules of Ruby Q. 2:
-
This week only – no waiting period!
-
Support Ruby Q. 2 by submitting ideas as often as you can! (A
permanent, new website is in the works for Ruby Q. 2. Until then,
please visit the temporary website at -
Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby T. follow the discussion. Please reply to
the original quiz message, if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Apologies for being late today… 'twas distracted by my English
report!
One-Liners Mashup (#177)
This week is going to be very informal, and without any particular
task or submission. It’s hunting season, and we’re hunting one-liners.
Basically, we’ll start with the simple problem I’ve presented below.
Your solution must fit in one line. (Golfing is okay, but not
necessary. One line generally means about 80 chars wide, but we’re
flexible here.) If you are writing a method, the def foo(args)
and
end
(and class Whatever
and end
for adding methods to a class)
doesn’t count… the body of the method will.
Of course, your solutions should be generally useful, and not hard-
coded to solve any particular example used to illustrate what the
solution should do.
Post your solution AND a followup problem for others to solve. Repeat
ad nauseum (or until about Wed/Thu).
Ready? Here goes. First problem…
You should know this pattern well:
> [:one, "two", 4] * 3
=> [:one, "two", 4, :one, "two", 4, :one, "two", 4]
Write a single line method on Array that does this instead:
> [:one, "two", 4].repeat(3)
=> [:one, :one, :one, "two", "two", "two", 4, 4, 4]