From 99c64829ce71ecf07b576960ea8ff01dfee61be7 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Mon, 8 Oct 2007 06:05:44 +0000 Subject: * Add Range#overlaps?(range), Range#include?(range), and Range#step without a block. [brandon] Closes #9746 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7800 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../core_ext/range/blockless_step.rb | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/range/blockless_step.rb (limited to 'activesupport/lib/active_support/core_ext/range/blockless_step.rb') 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 -- cgit v1.2.3