Issue #14473 has been updated by tarui (Masaya Tarui).


As real-world use-case, 
I want it(include,cover version) for guarding NArray's Index arguments.
NArray#[] can accept Integer and Range. 
Currently, to limit the access range, We have to write complex code.
~~~ ruby
def check(idx,range)
  case idx
  when Integer
    range.include?(idx)
  when Range
    range.begin < idx.begin && ( (!range.exclude_end? && !idx.exclude__end? || range.exclude_end?) ? range.end >=idx.end : range.end > idx.end)
  end
end 
~~~
I want to write simply 
~~~ ruby
range.include?(idx)
~~~







----------------------------------------
Feature #14473: Add Range#subrange?
https://bugs.ruby-lang.org/issues/14473#change-72930

* Author: greggzst (Grzegorz Jakubiak)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hi there,

I'd like to propose a method that returns true when a range that the method gets called on is a subrange of a range passed in as an argument.

Example:

~~~ ruby
(2..4).subrange?(1...4) 
=> true
(-2..2).subrange?(-1..3) 
=> false
~~~




---Files--------------------------------
0001-range.c-add-subset-superset-methods.patch (8.84 KB)
v2-0001-range.c-add-subset-superset-methods.patch (8.85 KB)
v3-0001-range.c-add-subrange-superrange-methods.patch (9.24 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>