Граф коммитов

329 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans c5475f4269 Fix Range#cover? returning true for beginless ranges of different types
Previously `(2..).cover?("2"..)` was false, but
`(..2).cover?(.."2")` was true.  This changes it so both are false,
treating beginless ranges the same as endless ranges in regards to
type checks.

This also adds documentation to #cover? to describe behavior with
beginless and endless ranges, testing each documentation example,
which is how this bug was found.

Fixes [Bug #18155]
2022-06-06 09:59:22 -07:00
Jeremy Evans f8724987db Document beginless, endless ranges in Range class documentation 2022-04-25 13:07:35 -07:00
Burdette Lamar ffcdbedbfb
Repaired What's Here sections for Range, String, Symbol, Struct (#5735)
Repaired What's Here sections for Range, String, Symbol, Struct.
2022-03-30 13:46:24 -05:00
Nobuyoshi Nakada 50c972a1ae
[DOC] Simplify operator method references 2022-02-12 12:38:36 +09:00
Jeremy Evans fd710d7e99 Fix Range#include? for beginless exclusive string ranges
Previously, include? would return true for the end of the range,
when it should return false because the range is exclusive.

Research and Analysis by Victor Shepelev.

Fixes [Bug #18577]
2022-02-09 19:47:28 -08:00
Nobuyoshi Nakada 8ca7b0b68a
[DOC] Fix broken links to operator methods
Once https://github.com/ruby/rdoc/pull/865 is merged, these hacks
are no longer needed.
2022-02-08 01:39:37 +09:00
Nobuyoshi Nakada 16fdc1ff46
[DOC] Fix broken links to literals.rdoc 2022-02-08 01:27:52 +09:00
Peter Zhu a32e5e1b97 [DOC] Use RDoc link style for links in the same class/module
I used this regex:

(?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+)

And performed a global find & replace for this:

rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Peter Zhu f9a2802bc5 [DOC] Use RDoc link style for links to other classes/modules
I used this regex:

([A-Za-z]+)\.html#(?:class|module)-[A-Za-z]+-label-([A-Za-z0-9\-\+]+)

And performed a global find & replace for this:

rdoc-ref:$1@$2
2022-02-07 09:52:06 -05:00
Burdette Lamar 28fb6d6b9e
Adding links to literals and Kernel (#5192)
* Adding links to literals and Kernel
2021-12-03 07:12:28 -06:00
S.H 75aae66c4f
Some codes replace to `RBOOL` macro (#5023)
* Some code replace and using RBOOL macro

* Fix indent

* Using RBOOL in syserr_eqq function
2021-11-09 17:09:29 +09:00
Nobuyoshi Nakada 4fb71575e2
[DOC] Fix code markup [ci skip]
Code markup in RDoc must not be concatenated with anothr word.
2021-10-25 01:04:51 +09:00
Nobuyoshi Nakada e2017f8c7c
Unify iteration arguments 2021-10-10 11:45:50 +09:00
Nobuyoshi Nakada 2293547d9b
Update iteration step in step_i_iter 2021-10-10 11:41:26 +09:00
S.H afb95d1004
Refactor sym_step_i function 2021-10-10 11:40:04 +09:00
S.H dc9112cf10
Using NIL_P macro instead of `== Qnil` 2021-10-03 22:34:45 +09:00
Jörg W Mittag fb03598666
Remove unnecessary checks in `Range#each` [Bug #18237]
In commit:7817a438eb1803e7b3358f43bd1f38479badfbdc, the implementation
of `Time#succ`, which had been deprecated for 10 years, was finally
removed.

During that time, there was an explicit `instance_of?` check in
source:range.c#L350 with a comment that the check should be removed
once `Time#succ` is removed.

Since `Time#succ` is now gone, this check should be removed.

Note: this should be coordinated with adding a version guard to the
corresponding check in ruby/spec as well.
2021-10-03 22:16:08 +09:00
Burdette Lamar 854fe9d1c1
Correct two errors in Range RDoc (#4889) 2021-09-23 18:08:49 -05:00
Burdette Lamar fb976df81f
What's Here for Range (#4881) 2021-09-22 14:51:11 -05:00
Burdette Lamar 736eb30e52
Enhanced RDoc for Range (#4870)
Introductory material revised.
2021-09-20 13:41:55 -05:00
Burdette Lamar 1c07c98229
Enhanced RDoc for Range (#4847)
Treated:

    #to_s
    #inspect
    #===
    #include?
    #cover?
    #count
2021-09-18 07:27:02 -05:00
Burdette Lamar 745287d43a
Enhanced RDoc for Range#minmax (#4846) 2021-09-15 15:51:54 -05:00
Burdette Lamar e967740d07
Enhanced RDoc for Range#max (#4844) 2021-09-15 14:48:47 -05:00
Burdette Lamar 97374c7eec
Enhanced RDoc for Range#min (#4842) 2021-09-15 13:37:34 -05:00
Nobuyoshi Nakada a27c274f04
[DOC] Fix broken links [ci skip]
* As the "doc/" prefix is specified by the `--page-dir` option,
  remove from the rdoc references.
* Refer to the original .rdoc instead of the converted .html.
2021-09-15 14:16:14 +09:00
Burdette Lamar a0357acf19
Enhanced RDoc for Range (#4839)
Treated:

    #size
    #to_a
    #each
    #begin
    #end
    #first
    #last
2021-09-14 17:51:31 -05:00
Burdette Lamar 1af5a0c574
Bsearch doc for Array and Range (#4838)
This PR creates doc/bsearch.rdoc to provide common documentation for bsearch in Array and Range.
2021-09-14 16:08:21 -05:00
Burdette Lamar 4e03032a83
Enhanced RDoc for Range (#4833)
Treated:

    ::new
    #include_end?
    #==
    #eql?
    #hash
    #step
2021-09-13 14:00:39 -05:00
S-H-GAMELINKS 83a5e2bb5c Using RB_FLOAT_TYPE_P macro 2021-09-12 11:16:31 +09:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
S-H-GAMELINKS e882905d0d Refactor sym_each_i function 2021-07-22 14:02:23 +09:00
Aaron Patterson 9f3adaf529 Use public allocators for creating new T_OBJECT objects
This way the header flags and object internals are set correctly
2020-10-28 18:35:22 -07:00
Kenta Murata f754b42285
numeric.c, range.c: prohibit zero step
* numeric.c: prohibit zero step in Numeric#step

* range.c: prohibit zero step in Range#step

* Fix ruby-spec

[Feature #15573]
2020-10-23 15:26:51 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Kenta Murata a6a8576e87
Feature #16812: Allow slicing arrays with ArithmeticSequence (#3241)
* Support ArithmeticSequence in Array#slice

* Extract rb_range_component_beg_len

* Use rb_range_values to check Range object

* Fix ary_make_partial_step

* Fix for negative step cases

* range.c: Describe the role of err argument in rb_range_component_beg_len

* Raise a RangeError when an arithmetic sequence refers the outside of an array

[Feature #16812]
2020-10-21 02:40:18 +09:00
Kenta Murata 18cecda46e
range.c: Fix an exception message in rb_range_beg_len
[Bug #17271]
2020-10-20 16:01:57 +09:00
Koichi Sasada 0096d2b895 freeze all Range objects.
Matz want to try to freeze all Range objects.
[Feature #15504]
2020-09-25 22:16:55 +09:00
Nobuyoshi Nakada 6321330461
Removed trailing spaces [ci skip] 2020-09-02 13:30:16 +09:00
Jeremy Evans de10a1f358 Update documentation for Range#max 2020-09-01 10:52:47 -07:00
Jeremy Evans 4db4faef0f Revert "Fix Range#{max,minmax} for range with integer beginning and non-integer end"
This reverts commit 8900a25581.
2020-09-01 10:52:47 -07:00
Jeremy Evans e080a4cdee Revert "Special case Range#max for integer beginning and Float::Infinity end"
This reverts commit 05bf811c28.
2020-09-01 10:52:47 -07:00
Jeremy Evans 05bf811c28 Special case Range#max for integer beginning and Float::Infinity end
Popular Ruby libraries such as Rails and Rubocop relying on the
previous behavior, even though it is technically a bug. The
correct behavior is probably raising RangeError, since that is what
an endless range raises.

Related to [Bug #17017]
2020-07-19 10:25:55 -04:00
Michael Kohl 8a5ad2b77d
Fix Range#max for beginless Integer ranges [Bug #17034]
* Fix Range#max for beginless Integer ranges
* Update test/ruby/test_range.rb
* Fix formatting

https://github.com/ruby/ruby/pull/3328

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2020-07-19 01:18:40 +09:00
Jeremy Evans 8900a25581
Fix Range#{max,minmax} for range with integer beginning and non-integer end
Previously, for inclusive ranges, the max would show up as the
end of the range, even though the end was not an integer and would
not be the maximum value.  For exclusive ranges, max/minmax would
previously raise a TypeError, even though it is possible to get the
correct maximum.

This change to max/minmax also uncovered a similar error in cover?,
which calls max in certain cases, so adjust the code there so that
cover? still works as expected.

Fixes [Bug #17017]
2020-07-13 10:09:38 -07:00
Jeremy Evans c146362555 Use static variables in Range#minmax 2020-07-04 13:34:38 -07:00
Sam Bostock bf1a6771f3 Fix non-numeric exclusive Range#minmax bug
The implementation of Range#minmax added in d5c60214c4 causes the
following incorrect behaviour:

  ('a'...'c').minmax => ["a", ["a", "b"]]

instead of

  ('a'...'c').minmax => ["a", "b"]

This is because the C implementation of Range#minmax (range_minmax)
directly delegates to the C implementation of Range#min (range_min) and
Range#max (range_max), without changing the execution context.

Range#max's C implementation (range_max), when given a non-numeric
exclusive range, delegates to super, which is meant to call
Enumerable#max. However, because range_max is called directly by
range_minmax, super calls Enumerable#minmax instead, causing the
incorrect nesting.

Perhaps it is possible to change the execution context in an optimized
manner, but the simplest solution seems to be to just explicitly
delegate from Range#minmax to Range#min and Range#max.
2020-07-04 10:02:24 -07:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 9c5804ac1c range_each: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00