I have a class Creator
which will execute a block code for a number of times. I'm not sure how to write this in a more elegant way in Ruby.
class Creator
attr_accessor :block
def self.create(&block)
@block = block
return self
end
def self.for(number)
0.upto(number) {
block.call
}
end
end
And this is how I call it which I want to stay like this.
Creator.create{
SomeModel.create!(@attr)
}.for(30)
30.times { SomeModel.create!(@attr) }
. – tokland Jan 14 '14 at 11:16