Issue #12133 has been updated by Ryan Hosford.


Please accept apologies for confusion caused by non-matching parenthesis/brackets -- this notation is just a standard way of denoting intervals in mathematics (ref. [ISO 31-11](https://en.wikipedia.org/wiki/ISO_31-11) & [Wikipedia entry for including excluding endpoints in intervals](https://en.wikipedia.org/wiki/Interval_(mathematics)#Including_or_excluding_endpoints)).

I'm not proposing we support non-matching parenthesis or brackets. Here's what I'm proposing:

~~~
# Including both endpoints ("a" and "b").
(a..b)

# Excluding endpoint "b"
(1...10) # OR
(1..10).exclude_end

# Excluding endpoint "a"
(1..10).exclude_start

# Excludes both endpoints ("a" and "b").
(1...10).exclude_start # OR
(1..10).exclude_start.exclude_end
~~~

I think this is useful because it would give the ruby language a more complete implementation of ranges/intervals. I recently built a feature that requires me to cover the range from **a** to **b** with 2-5 sub-ranges, validating that there are no gaps and no overlaps in the sub-ranges. I also needed to be flexible with which sub-range an endpoint should fall. Examples: If your systolic blood pressure is 120 mmHg, do I say you are in a normal range or do I say you have Prehypertension? If your HBA1C is 6.5%, are you in a pre-diabetic condition or do you have diabetes?

I believe I could've written a simpler solution with a more complete range implementation.

Thank you, Shyouhei and Nobu, for your responses.

----------------------------------------
Feature #12133: Ability to exclude start when defining a range
https://bugs.ruby-lang.org/issues/12133#change-57661

* Author: Ryan Hosford
* Status: Feedback
* Priority: Normal
* Assignee: 
----------------------------------------
An intuitive, approach would be to allow defining ranges like so:

~~~
[1..10]
[1..10)
(1..10]
(1..10)
~~~

... where a square bracket indicates boundary inclusion and a parenthesis represents boundary exclusion. The syntax there is obviously not going to work, but it demonstrates the idea.

A more feasible, still intuitive, solution might look like the following

~~~
(1..10)                # [1..10]
(1...10)               # [1..10) ... Alternatively: (1..10).exclude_end
(1..10).exclude_start  # (1..10]
(1...10).exclude_start # (1..10) ... Alternatively: (1..10).exclude_start.exclude_end
~~~

For consistency, I think we'd also want to add `#exclude_start?` & `#exclude_end` methods.



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