Numeric#of

Ara,

i end up doing this sort of thing alot:

avg, max, min = {}, {}, {}

stack_a, stack_b = ,

and was thinking about a general syntax for ‘n of these’ or
‘n of the result of this block’… does this read alright?

~ > cat of.rb
class Numeric
def of
ret =
times{|i| ret << yield(i)}
ret
end
end

them = 3.of{ Array.new }
p them # => [,,]

I'm sure you've already thought about this, but just in case you

haven’t:

them = (1…3).collect( Array.new )

…or…

them = (1…3).map( Array.new)
p them # => [,,]

It's almost as clean as your Numeric (shouldn't that be Integer?)

#of method.

- Warren Brown