---
title: "Ruby 2.6 Range#cover? accepts Range object as argument"
description: "Ruby 2.6 Range#cover? now accepts Range object as an argument"
canonical_url: "https://www.bigbinary.com/blog/ruby-2-6-range-cover-now-accepts-range-object"
markdown_url: "https://www.bigbinary.com/blog/ruby-2-6-range-cover-now-accepts-range-object.md"
---

# Ruby 2.6 Range#cover? accepts Range object as argument

Ruby 2.6 Range#cover? now accepts Range object as an argument

- Author: Abhay Nikam
- Published: October 24, 2018
- Categories: Ruby 2.6, Ruby

`Range#cover?` returns true if the object passed as argument is in the range.

```ruby
(1..10).cover?(5)
=> true
```

`Range#cover?` returns false if the object passed as an argument is
non-comparable or is not in the range.

Before Ruby 2.6, `Range#cover?` used to return false if a Range object is passed
as an argument.

```ruby
>> (1..10).cover?(2..5)
=> false
```

#### Ruby 2.6

In Ruby 2.6 `Range#cover?` can accept a Range object as an argument. It returns
true if the argument Range is equal to or a subset of the Range.

```ruby
(1..100).cover?(10..20)
=> true

(1..10).cover?(2..5)
=> true

(5..).cover?(4..)
=> false

("a".."d").cover?("x".."z")
=> false
```

Here is relevant
[commit](https://github.com/ruby/ruby/commit/9ca738927293df1c7a2a1ed7e2d6cf89527b5438)
and [discussion](https://bugs.ruby-lang.org/issues/14473) for this change.

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2-6-range-cover-now-accepts-range-object)
