399 Commits
Author SHA1 Message Date
Burdette Lamar 536dc6f98b [DOC] Doc for Range class (#19427) 2026-10-21 16:29:43 +09:00
Hiroshi SHIBATAandClaude Opus 5 7e14bab584 Use rb_len_t for lengths in range.c
rb_range_component_beg_len() converts range endpoints used as indices, and Range#first, #last and #max take element counts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 14:00:15 +09:00
Hiroshi SHIBATAandClaude Opus 5 cc3ba11012 Use rb_len_t in the C API for lengths and indices
Once rb_len_t widens this changes the `long *` output parameters of rb_range_beg_len(), rb_str_subpos(), rb_arithmetic_sequence_beg_len_step(), ruby_enc_find_basename() and ruby_enc_find_extname(), so extensions passing `long *` to them will need to be updated. The extension guides list these signatures verbatim and follow along.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 14:00:15 +09:00
Étienne Barrié d74c656be9 Document Range attributes begin and end 2026-09-23 18:47:54 +02:00
Peter Zhu f336732287 ZJIT: Centralize shape setting for ZJIT GC fastpath
This commit centralizes shape setting for objects in the ZJIT GC fastpath
into the rb_zjit_new_obj_shape function to avoid each type having to deal
with shapes individually.
2026-08-07 16:31:14 -04:00
Ajay Krishnan 45f530d48e [DOC] Fix Range#step return value example (#17938) 2026-07-26 11:03:28 -04:00
Jean Boussier 8645a948c0 Right size temporary dump objects
The Range Marshal compat dumper would allocate
an Object with no size information, hence get a 32B slot
with enough space for 2 ivars, then insert 3 ivars causing
it to spill.

This isn't a big problem, but somewhat shows that the interface
isn't WVA aware.

By introducing `rb_class_allocate_instance_capa` we can directly
allocate an object with enough room.
2026-07-22 23:52:01 +02:00
Peter Zhu 9438d7fd1e Implement GC fast path for new_range_fixnum
Benchmark:

    i = 0
    def run(max)
      i = 0
      while i < max
        a = i..100
        i += 1
      end
    end

    30.times { run(2) }
    run(10_000_000)

Result:

    Benchmark 1: master
      Time (mean ± σ):     229.8 ms ±   3.2 ms    [User: 221.7 ms, System: 6.2 ms]
      Range (min … max):   226.3 ms … 235.2 ms    12 runs

    Benchmark 2: branch
      Time (mean ± σ):      67.4 ms ±   2.0 ms    [User: 60.4 ms, System: 5.3 ms]
      Range (min … max):    65.1 ms …  75.1 ms    43 runs

    Summary
      branch ran
        3.41 ± 0.11 times faster than master
2026-07-22 15:32:04 -04:00
Jean Boussier 60fb0baeaf Define Range#begin and Range#end as optimized methods
Since Range is a struct, might as well use optimized accessors.
2026-07-21 16:47:19 +02:00
Jean BoussierandJohn Hawthorn 40f105bd55 Change RStruct to match SHAPE_ID_LAYOUT_EXTENDED
THe downside is that we now always reserve one 8B reference for the
IMEMO/fields, even for structs that never have any ivars.

But it is an acceptable tradeoff given that ivars on structs aren't
rare.

Co-Authored-By: John Hawthorn <john@hawthorn.email>
2026-07-21 08:30:12 +02:00
Nobuyoshi Nakada 513875464f [Feature #22175] Add Range#clamp
Return a new Range with its begin and end clamped to given
bounds, either as `clamp(min, max)` or `clamp(range)`.
2026-07-16 00:14:09 +09:00
Kouhei Yanagita 85453b75b1 Use OPTIMIZED_CMP in r_less instead of <=> 2026-03-06 13:12:20 +09:00
Earlopain b093886df0 [DOC] Fix range docs intro
It's code but not formatted as such
2026-02-20 13:19:52 +09:00
Peter Zhu 491e38902c [DOC] Fix links to What's Here
The RDoc link format has changed so these are all broken links.
2026-01-26 17:18:19 -05:00
Burdette Lamar 58fb95af36 [DOC] Harmonize #== methods (#15805) 2026-01-06 17:13:15 -05:00
BurdetteLamar dd67874ad9 [DOC] Harmonize #=== methods 2026-01-05 18:30:40 -05:00
Jeremy Evans 38701a4de8 Remove deprecated support for to_set taking arguments 2025-12-29 14:54:41 +09:00
Victor Shepelev ec4ca91319 Small documentation adjustments for new/updated features (#15634)
* Document Range#to_set

* Update Thread#raise and Fiber#raise signatures and docs

* Add reference to String#strip to character_selectors.rdoc

* Update *nil docs when calling methods

* Enhance Array#find and #rfind docs

* Add a notice to Kernel#raise about cause:
2025-12-20 13:07:38 +02:00
Stan Lo 4cd6661e18 Reorganize page documentations (#15154)
Re-organize page docs
2025-11-27 20:12:24 +00:00
Akinori Musha 61500c6f48 Add size checks to Range#to_set and Enumerator#to_set [Bug #21654]
These two class are most common sources of infinite sequences.  This change should effectively prevent accidental infinite loops when calling to_set on them. [Bug #21513]
2025-11-13 22:00:07 +09:00
Alan Wu 6b197dec48 ZJIT: Mark Insn::NewRange as having side effects 2025-08-19 15:54:12 -04:00
flavio-b 80ab42462e [DOC] beginless and endless ranges inspect returns "nil..nil" always
Small correction to the Range docs. All beginless (nil..) and endless (..nil) ranges, as well as fully open ranges (nil..nil), display "nil..nil" when inspected, regardless of their original syntax.
2025-03-21 10:30:40 +09:00
Jérôme Parent-Lévesque b5cdbadeed [Bug #21185] Fix Range#overlap? with infinite range
Infinite ranges, i.e. unbounded ranges, should overlap with any other range
which wasn't the case in the following example: (0..3).overlap?(nil..nil)
2025-03-17 16:26:23 +09:00
Nobuyoshi Nakada cbe3156f82 [Bug #21174] [Bug #21175] Fix Range#max on beginless integer range 2025-03-07 17:23:33 +09:00
Nobuyoshi Nakada f56f3eaae5 [Bug #21030] Fix step for non-numeric range
When the end points of an inclusive range equal, `Range#step` should
yields the element once.
2025-01-13 02:07:05 +09:00
Nobuyoshi Nakada e433e6515e [DOC] Exclude 'Class' and 'Module' from RDoc's autolinking 2025-01-02 12:36:06 +09:00
Nobuyoshi Nakada b4ec22fe6c [DOC] Exclude 'Method' from RDoc's autolinking 2025-01-02 12:23:49 +09:00
Kouhei Yanagita 3422bfcab6 [Bug #20936] Fix #size for Range#reverse_each 2024-12-10 23:12:27 +09:00
John Bampton 3fc1495c30 Fix spelling 2024-10-09 07:14:44 +09:00
Peter Zhu dc83de4928 [DOC] Add missing word 2024-10-03 09:28:13 -04:00
Peter Zhu f56be4286f [DOC] Add pound sign before all <=> methods 2024-10-03 09:28:13 -04:00
Peter Zhu e358104e6e [DOC] Fix formatting for ways to create Range objects 2024-09-18 15:18:07 -04:00
Nobuyoshi Nakada 24493779b7 [Bug #20725] Should not call compare on nil-endpoint
It means unbounded, always inclusive of other ranges.
2024-09-13 18:23:28 +09:00
zverok d7b0f26963 Return back legacy Range#step behavior for symbol ranges 2024-09-09 17:46:13 +09:00
zverok 245ed2fc89 Range#step: restore legacy behavior for String ranges 2024-09-03 16:21:42 +09:00
Nobuyoshi Nakada cd0d4ec059 Single letter ASCII operator is same as the corresponding ID 2024-08-19 19:50:08 +09:00
Victor Shepelev d450f9d6a2 Make Range#step to consistently use + for iteration (#7444)
Make Range#step to consistently use + for iteration [Feature #18368]

Previously, non-numerics expected step to be integer,
and iterated with begin#succ, skipping over step value
steps. Since this commit, numeric and non-numeric iteration
behaves the same way, by using + operator.
2024-08-18 13:15:18 +03:00
Iskren 371790165f [DOC] Fix and improve array slicing example in range.c
* [DOC] Fix typo in range.c

  In the example of the beginless range used for array slicing,
  '..' range literal was used while the '...' literal was expected

* [DOC] Add example for array slicing in range.c

  Add an example for the array slice with the beginless range
  using the '..' range literal

* [DOC] Add comments for array slicing in range.c

  Add comments to make crystal clear what the '..' and '...'
  range literals do when used for array slicing as beginless range
2024-07-17 11:42:29 +09:00
Kouhei Yanagita 9f6deaa688 [Misc #18984] Raise TypeError from Range#size if the range is not iterable 2024-04-10 07:28:07 -07:00
Nobuyoshi Nakada b176315827 [Bug #20324] Uncomparable ranges are not overlapping 2024-03-04 21:02:08 +09:00
Yusuke Endoh 25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09:00
Peter Zhu 3ed5962755 Replace assert with RUBY_ASSERT in range.c
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
2024-02-12 15:07:47 -05:00
Peter Zhu 9ec4eae0b1 [DOC] Fix invalid syntax in Range#eql? 2023-12-27 19:31:56 -05:00
Kouhei Yanagita e8639098ed [Bug #19977] Fix (nil..nil) === x not to raise TypeError 2023-12-22 16:15:33 +09:00
Victor Shepelev 570d7b2c3e [DOC] Adjust some new features wording/examples. (#9183)
* Reword Range#overlap? docs last paragraph.

* Docs: add explanation about Queue#freeze

* Docs: Add :rescue event docs for TracePoint

* Docs: Enhance Module#set_temporary_name documentation

* Docs: Slightly expand Process::Status deprecations

* Fix MatchData#named_captures rendering glitch

* Improve Dir.fchdir examples

* Adjust Refinement#target docs
2023-12-14 23:01:48 +02:00
Victor Shepelev 07734b51c6 [DOC] Small fixes for documentation rendering
Mostly just fixing RDoc's incorrect treatment of `+`
2023-12-09 13:54:33 +09:00
Kouhei Yanagita 1a16b6ffc2 Make Range#reverse_each raise TypeError if endless 2023-11-28 15:10:42 +09:00
Burdette Lamar b92a92a3ff [DOC] More on JSON extensions (#8898) 2023-11-16 08:28:07 -08:00
Tanaka Akira c23b25f75f describe the assumption for Range#overlap?.
Range#overlap? assumes that there is no minimum value.
This assumption makes
+(...-Float::INFINITY).overlap?((...-Float::INFINITY))+ returns true
while +(...-Float::INFINITY)+ is empty.
2023-10-13 00:00:58 +09:00
Kouhei Yanagita 66fabefa03 Add Range#reverse_each implementation for performance 2023-10-12 17:34:49 +09:00