Issue #12133 has been updated by Ryan Hosford.


Here's what I would've written: (see: sample [range_sections](https://gist.githubusercontent.com/rthbound/aa6b4053c5791efb0904/raw/d7683f1cc54718efb905435ff794107a4c6ca80c/samples.rb))

~~~
def which_range?(value)
  range = nil

  range_sections.each do |rs|
    range = Range.new(rs.start, rs.end, rs.end_condition == "=", rs.start_condition == "=")

    break if range.include?(value)

    return nil
  end

  range
end
~~~

And here is what I can write with what's possible now:

~~~
def which_range?(value)
  range = nil

  range_sections.each do |rs|
    range = Range.new(rs.start, rs.end, rs.end_condition == "=")

    break if range.include?(value) && (value != range.begin && rs.start_condition != "=")

    return nil
  end

  range
end
~~~


I believe the first is more clear. The real benefit to the first is that the returned range would convey the appropriate boundary information.

What this issue is asking: 

* Is `#exclude_end?` meaningful and useful?
* Would `#exclude_start?` also be meaningful and useful?
* If `#exclude_end?` is meaningful and useful, should we add `#exclude_start?`?

If we decide we want it, we'd need to consider another thing:

* Do we need a shorthand? (something like the neko operator as Nobu mentioned). Examples:

~~~
^1..10^ #=> something we can't do now, but equivalent to ^1...10: 1  through 10, excluding both 1 and 10
10...20 #=> something we can do now, it is equivalent to 10..20^: 10 through 20, excluding 20
20..30  #=> something we can do now, it is equivalent to 10..20:  20 through 30
~~~


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

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