Issue #14473 has been updated by owst (Owen Stephens).


+1 for this suggestion - we have a similar method in our code base, implemented approximately as follows:

~~~ ruby
Range.class_exec do
  def subset?(other)
    raise ArgumentError unless other.is_a?(Range)

    first >= other.first && last <= other.last
  end
end
~~~

As a `Range` represents a set of elements, should there also be `proper_subset?`, `superset?` and `proper_superset?` methods (and perhaps their operator aliases) similar to those on `Set` (http://ruby-doc.org/stdlib-2.4.2/libdoc/set/rdoc/Set.html)?

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

* Author: greggzst (Grzegorz Jakubiak)
* Status: Open
* 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
~~~






-- 
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>