aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-03-29 02:43:13 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-03-29 02:43:13 -0700
commit48068bc1a4bbb272def06139fab392cf964ddc8a (patch)
tree2542fc0e9725ea98c38bb2b1275e611e15ba2ab5 /activesupport/lib
parentda8ade36b3dccc4e85a4d95a89c7700eaac367c0 (diff)
downloadrails-48068bc1a4bbb272def06139fab392cf964ddc8a.tar.gz
rails-48068bc1a4bbb272def06139fab392cf964ddc8a.tar.bz2
rails-48068bc1a4bbb272def06139fab392cf964ddc8a.zip
Feature detection for Range#step extension
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/range/blockless_step.rb17
1 files changed, 10 insertions, 7 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 98f333786d..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,21 +1,24 @@
class Range
- if RUBY_VERSION < '1.9'
+ 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(value = 1, &block)
+ def step_with_blockless(*args, &block)
if block_given?
- step_without_blockless(value, &block)
+ step_without_blockless(*args, &block)
else
array = []
- step_without_blockless(value) { |step| array << step }
+ step_without_blockless(*args) { |step| array << step }
array
end
end
else
- def step_with_blockless(value = 1, &block) #:nodoc:
+ def step_with_blockless(*args, &block) #:nodoc:
if block_given?
- step_without_blockless
+ step_without_blockless(*args, &block)
else
- step_without_blockless(value).to_a
+ step_without_blockless(*args).to_a
end
end
end