diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-04-22 15:26:03 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-04-22 15:26:03 +0100 |
commit | 5f3f100ce2d689480da85abc88e5e940cf90189e (patch) | |
tree | 15c1a05a5308a9eea56d7f0889ac46d9cac5b57c /activesupport/lib/active_support/core_ext/range/blockless_step.rb | |
parent | d758d996d1b66e2a65640f79f01ce2ac674d7ed5 (diff) | |
parent | ca49299434bc764b667cd86846d892e91a150ef3 (diff) | |
download | rails-5f3f100ce2d689480da85abc88e5e940cf90189e.tar.gz rails-5f3f100ce2d689480da85abc88e5e940cf90189e.tar.bz2 rails-5f3f100ce2d689480da85abc88e5e940cf90189e.zip |
Merge branch 'master' into active_model
Conflicts:
activeresource/lib/active_resource/validations.rb
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 | 51 |
1 files changed, 23 insertions, 28 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 index 6fa1eb5bee..f4792d03b7 100644 --- a/activesupport/lib/active_support/core_ext/range/blockless_step.rb +++ b/activesupport/lib/active_support/core_ext/range/blockless_step.rb @@ -1,32 +1,27 @@ -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module Range #:nodoc: - # Return an array when step is called without a block. - module BlocklessStep - def self.included(base) #:nodoc: - base.alias_method_chain :step, :blockless - end - - if RUBY_VERSION < '1.9' - def step_with_blockless(value = 1, &block) - if block_given? - step_without_blockless(value, &block) - else - returning [] do |array| - step_without_blockless(value) { |step| array << step } - end - end - end - else - def step_with_blockless(value = 1, &block) - if block_given? - step_without_blockless(value, &block) - else - step_without_blockless(value).to_a - end - end - end +class Range + begin + (1..2).step + # Range#step doesn't return an Enumerator + rescue LocalJumpError + # Return an array when step is called without a block. + def step_with_blockless(*args, &block) + if block_given? + step_without_blockless(*args, &block) + else + array = [] + step_without_blockless(*args) { |step| array << step } + array + end + end + else + def step_with_blockless(*args, &block) #:nodoc: + if block_given? + step_without_blockless(*args, &block) + else + step_without_blockless(*args).to_a end end end + + alias_method_chain :step, :blockless end |