diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/range/blockless_step.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/blockless_step.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/range/blockless_step.rb b/activesupport/lib/active_support/core_ext/range/blockless_step.rb new file mode 100644 index 0000000000..4d5e27457b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/range/blockless_step.rb @@ -0,0 +1,25 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Range #:nodoc: + # Return and array when step is called without a block + module BlocklessStep + + def self.included(klass) #:nodoc: + klass.send(:alias_method, :step_with_block, :step) + klass.send(:alias_method, :step, :step_without_block) + end + + def step_without_block(value, &block) + if block_given? + step_with_block(value, &block) + else + returning [] do |array| + step_with_block(value) {|step| array << step } + end + end + end + + end + end + end +end
\ No newline at end of file |