Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 30 lines (27 sloc) 0.699 kb
f28bd95 @jeremy Fix dependencies revealed by testing in isolation
jeremy authored
1 require 'active_support/core_ext/module/aliasing'
2
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
3 class Range
48068bc @jeremy Feature detection for Range#step extension
jeremy authored
4 begin
5 (1..2).step
6 # Range#step doesn't return an Enumerator
7 rescue LocalJumpError
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
8 # Return an array when step is called without a block.
48068bc @jeremy Feature detection for Range#step extension
jeremy authored
9 def step_with_blockless(*args, &block)
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
10 if block_given?
48068bc @jeremy Feature detection for Range#step extension
jeremy authored
11 step_without_blockless(*args, &block)
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
12 else
13 array = []
48068bc @jeremy Feature detection for Range#step extension
jeremy authored
14 step_without_blockless(*args) { |step| array << step }
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
15 array
16 end
17 end
18 else
48068bc @jeremy Feature detection for Range#step extension
jeremy authored
19 def step_with_blockless(*args, &block) #:nodoc:
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
20 if block_given?
48068bc @jeremy Feature detection for Range#step extension
jeremy authored
21 step_without_blockless(*args, &block)
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
22 else
48068bc @jeremy Feature detection for Range#step extension
jeremy authored
23 step_without_blockless(*args).to_a
99c6482 @NZKoz * Add Range#overlaps?(range), Range#include?(range), and Range#step w…
NZKoz authored
24 end
25 end
26 end
da8ade3 @jeremy Convert Range step and include extension modules to class reopen
jeremy authored
27
28 alias_method_chain :step, :blockless
d556f46 @jeremy Style update for new Range extensions
jeremy authored
29 end
Something went wrong with that request. Please try again.