mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
added Range#count? for Ruby 1.8
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
committed by
Santiago Pastorino
parent
289cc15f1a
commit
b0da0dd834
@@ -2,3 +2,4 @@ require 'active_support/core_ext/range/blockless_step'
|
||||
require 'active_support/core_ext/range/conversions'
|
||||
require 'active_support/core_ext/range/include_range'
|
||||
require 'active_support/core_ext/range/overlaps'
|
||||
require 'active_support/core_ext/range/cover'
|
||||
|
||||
3
activesupport/lib/active_support/core_ext/range/cover.rb
Normal file
3
activesupport/lib/active_support/core_ext/range/cover.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Range
|
||||
alias_method(:cover?, :include?) unless instance_methods.include?(:cover?)
|
||||
end
|
||||
@@ -62,4 +62,16 @@ class RangeTest < Test::Unit::TestCase
|
||||
(1..10).step(2) {|i| array << i }
|
||||
assert_equal [1,3,5,7,9], array
|
||||
end
|
||||
|
||||
if RUBY_VERSION < '1.9'
|
||||
def test_cover
|
||||
assert((1..3).cover?(2))
|
||||
assert !(1..3).cover?(4)
|
||||
end
|
||||
else
|
||||
def test_cover_is_not_override
|
||||
range = (1..3)
|
||||
assert range.method(:include?) != range.method(:cover?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user