core/range.rbs in rbs-3.3.2 vs core/range.rbs in rbs-3.4.0.pre.1
- old
+ new
@@ -174,10 +174,12 @@
# * [Creating a Range](rdoc-ref:Range@Methods+for+Creating+a+Range)
# * [Querying](rdoc-ref:Range@Methods+for+Querying)
# * [Comparing](rdoc-ref:Range@Methods+for+Comparing)
# * [Iterating](rdoc-ref:Range@Methods+for+Iterating)
# * [Converting](rdoc-ref:Range@Methods+for+Converting)
+# * [Methods for Working with
+# JSON](rdoc-ref:Range@Methods+for+Working+with+JSON)
#
#
# ### Methods for Creating a Range
#
# * ::new: Returns a new range.
@@ -223,10 +225,23 @@
#
# * #inspect: Returns a string representation of `self` (uses #inspect).
# * #to_a (aliased as #entries): Returns elements of `self` in an array.
# * #to_s: Returns a string representation of `self` (uses #to_s).
#
+#
+# ### Methods for Working with JSON
+#
+# * ::json_create: Returns a new Range object constructed from the given
+# object.
+# * #as_json: Returns a 2-element hash representing `self`.
+# * #to_json: Returns a JSON string representing `self`.
+#
+#
+# To make these methods available:
+#
+# require 'json/add/range'
+#
class Range[out Elem] < Object
include Enumerable[Elem]
# <!--
# rdoc-file=range.c
@@ -554,12 +569,10 @@
# ('a'..'d').include?('cc') # => false
# ('a'..'d').cover?('cc') # => true
#
# Related: Range#cover?.
#
- # Range#member? is an alias for Range#include?.
- #
def include?: (untyped obj) -> bool
# <!--
# rdoc-file=range.c
# - Range.new(begin, end, exclude_end = false) -> new_range
@@ -808,10 +821,95 @@
| (Integer n) -> ::Array[Elem]
| (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
# <!--
# rdoc-file=range.c
+ # - overlap?(range) -> true or false
+ # -->
+ # Returns `true` if `range` overlaps with `self`, `false` otherwise:
+ #
+ # (0..2).overlap?(1..3) #=> true
+ # (0..2).overlap?(3..4) #=> false
+ # (0..).overlap?(..0) #=> true
+ #
+ # With non-range argument, raises TypeError.
+ #
+ # (1..3).overlap?(1) # TypeError
+ #
+ # Returns `false` if an internal call to `<=>` returns `nil`; that is, the
+ # operands are not comparable.
+ #
+ # (1..3).overlap?('a'..'d') # => false
+ #
+ # Returns `false` if `self` or `range` is empty. "Empty range" means that its
+ # begin value is larger than, or equal for an exclusive range, its end value.
+ #
+ # (4..1).overlap?(2..3) # => false
+ # (4..1).overlap?(..3) # => false
+ # (4..1).overlap?(2..) # => false
+ # (2...2).overlap?(1..2) # => false
+ #
+ # (1..4).overlap?(3..2) # => false
+ # (..4).overlap?(3..2) # => false
+ # (1..).overlap?(3..2) # => false
+ # (1..2).overlap?(2...2) # => false
+ #
+ # Returns `false` if the begin value one of `self` and `range` is larger than,
+ # or equal if the other is an exclusive range, the end value of the other:
+ #
+ # (4..5).overlap?(2..3) # => false
+ # (4..5).overlap?(2...4) # => false
+ #
+ # (1..2).overlap?(3..4) # => false
+ # (1...3).overlap?(3..4) # => false
+ #
+ # Returns `false` if the end value one of `self` and `range` is larger than, or
+ # equal for an exclusive range, the end value of the other:
+ #
+ # (4..5).overlap?(2..3) # => false
+ # (4..5).overlap?(2...4) # => false
+ #
+ # (1..2).overlap?(3..4) # => false
+ # (1...3).overlap?(3..4) # => false
+ #
+ # This method assumes that there is no minimum value because Ruby lacks a
+ # standard method for determining minimum values. This assumption is invalid.
+ # For example, there is no value smaller than `-Float::INFINITY`, making
+ # `(...-Float::INFINITY)` an empty set. Consequently, `(...-Float::INFINITY)`
+ # has no elements in common with itself, yet
+ # `(...-Float::INFINITY).overlap?((...-Float::INFINITY))<tt> returns true due to
+ # this assumption. In general, if <tt>r = (...minimum); r.overlap?(r)` returns
+ # `true`, where `minimum` is a value that no value is smaller than. Such values
+ # include `-Float::INFINITY`, `[]`, `""`, and classes without subclasses.
+ #
+ # Related: Range#cover?.
+ #
+ def overlap?: (Range[untyped]) -> bool
+
+ # <!--
+ # rdoc-file=range.c
+ # - reverse_each {|element| ... } -> self
+ # - reverse_each -> an_enumerator
+ # -->
+ # With a block given, passes each element of `self` to the block in reverse
+ # order:
+ #
+ # a = []
+ # (1..4).reverse_each {|element| a.push(element) } # => 1..4
+ # a # => [4, 3, 2, 1]
+ #
+ # a = []
+ # (1...4).reverse_each {|element| a.push(element) } # => 1...4
+ # a # => [3, 2, 1]
+ #
+ # With no block given, returns an enumerator.
+ #
+ def reverse_each: () { (Elem) -> void } -> self
+ | () -> ::Enumerator[Elem, self]
+
+ # <!--
+ # rdoc-file=range.c
# - size -> non_negative_integer or Infinity or nil
# -->
# Returns the count of elements in `self` if both begin and end values are
# numeric; otherwise, returns `nil`:
#
@@ -944,10 +1042,8 @@
#
# ('a'..'d').include?('cc') # => false
# ('a'..'d').cover?('cc') # => true
#
# Related: Range#cover?.
- #
- # Range#member? is an alias for Range#include?.
#
def member?: (untyped obj) -> bool
end