ml.ruby-lang.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

ruby-core

Thread Start a new thread
Download
Threads by month
  • ----- 2025 -----
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
ruby-core@ml.ruby-lang.org

  • 2 participants
  • 3310 discussions
[ruby-core:113189] [Ruby master Feature#19590] Include the invalid argument in error messages from `Process.clock_gettime` and `Process.clock_getres`
by nobu (Nobuyoshi Nakada) 11 Apr '23

11 Apr '23
Issue #19590 has been reported by nobu (Nobuyoshi Nakada). ---------------------------------------- Feature #19590: Include the invalid argument in error messages from `Process.clock_gettime` and `Process.clock_getres` https://bugs.ruby-lang.org/issues/19590 * Author: nobu (Nobuyoshi Nakada) * Status: Open * Priority: Normal ---------------------------------------- The argument of `Process.clock_gettime` and `Process.clock_getres` is complex a little, it supports `Integer` and `Symbol` which are platform dependent. In most cases, available clocks are defined as constants under `Process`, but on some platforms (MinGW at least) some constants are defined but fails with `EINVAL`, and the exception doesn't tell what was wrong. ```shell-session $ ./ruby --disable=gems -v -e 'Process.constants.grep(/\ACLOCK_/).each {|c| clk = Process.const_get(c); p [c, clk, (Process.clock_gettime(clk) rescue $!)]}' ruby 3.3.0dev (2023-02-23T18:13:13Z master 1fdaa06660) [x64-mingw-ucrt] [:CLOCK_REALTIME_COARSE, 4, #<Errno::EINVAL: Invalid argument - clock_gettime>] [:CLOCK_REALTIME, 0, 1681206710.103821] [:CLOCK_MONOTONIC, 1, 167731.5111065] [:CLOCK_PROCESS_CPUTIME_ID, 2, #<Errno::EINVAL: Invalid argument - clock_gettime>] [:CLOCK_THREAD_CPUTIME_ID, 3, #<Errno::EINVAL: Invalid argument - clock_gettime>] ``` And it wastes time when passing a `Symbol` with typo. So my proposal is to add the argument to the exception message. ```shell-session $ ./miniruby -e 'p Process.clock_gettime(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME)' -e:1:in `clock_gettime': Invalid argument - clock_gettime(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME) (Errno::EINVAL) from -e:1:in `<main>' ``` -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:113059] [Ruby master Bug#19563] Ripper.tokenize(code).join != code when heredoc and multiline %w[] literal is on the same line
by tompng (tomoya ishida) 11 Apr '23

11 Apr '23
Issue #19563 has been reported by tompng (tomoya ishida). ---------------------------------------- Bug #19563: Ripper.tokenize(code).join != code when heredoc and multiline %w[] literal is on the same line https://bugs.ruby-lang.org/issues/19563 * Author: tompng (tomoya ishida) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0dev (2023-03-29T21:57:52Z master 1b06422767) [x86_64-linux] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ~~~ruby Ripper.tokenize "<<EOF || %w[hello\nEOF\n\n\n\nworld]" # actual result ["<<EOF", " ", "||", " ", "%w[", "hello", "\n\n\n\n", "EOF\n", "world", "]"] # expected result ["<<EOF", " ", "||", " ", "%w[", "hello", "\n", "EOF\n", "\n\n\n", "world", "]"] ~~~ same for `%i[]` literal. -- https://bugs.ruby-lang.org/
3 5
0 0
[ruby-core:113162] [Ruby master Bug#19586] Rails CI fails since 89bdf6e94cb36567478c509722fe98069402fb8e and RUBY_YJIT_ENABLE=1
by yahonda (Yasuo Honda) 10 Apr '23

10 Apr '23
Issue #19586 has been reported by yahonda (Yasuo Honda). ---------------------------------------- Bug #19586: Rails CI fails since 89bdf6e94cb36567478c509722fe98069402fb8e and RUBY_YJIT_ENABLE=1 https://bugs.ruby-lang.org/issues/19586 * Author: yahonda (Yasuo Honda) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0dev (2023-04-06T15:34:58Z master 89bdf6e94c) [x86_64-linux] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Rails CI against Ruby master with yjit-enabled fails https://buildkite.com/rails/rails/builds/95521#018761e7-3d48-4666-a8cd-d133… According to git bisect, it is triggered by 89bdf6e94cb36567478c509722fe98069402fb8e ### Steps to reproduce ``` git clone https://github.com/rails/rails cd rails/activerecord bundle install RUBY_YJIT_ENABLE=1 bin/test ``` ### Expected behavior It should pass ### Actual behavior ```ruby $ ruby -v ; RUBY_YJIT_ENABLE=1 bin/test ruby 3.3.0dev (2023-04-06T15:34:58Z master 89bdf6e94c) [x86_64-linux] Using sqlite3 /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:30:in `instance_method': undefined method `comments_count_will_change!' for module `#<Module:0x00007fb53d644b10>' (NameError) owner.define_method(name, @cache.instance_method(as)) ^^^^^^^^^^^^^^^^ from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:30:in `block in apply' from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:29:in `each' from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:29:in `apply' from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:61:in `block in execute' from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:60:in `each_value' from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:60:in `execute' from /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/code_generator.rb:42:in `batch' from /home/yahonda/src/github.com/rails/rails/activemodel/lib/active_model/attribute_methods.rb:206:in `alias_attribute' from /home/yahonda/src/github.com/rails/rails/activerecord/test/models/post.rb:28:in `<class:Post>' from /home/yahonda/src/github.com/rails/rails/activerecord/test/models/post.rb:3:in `<top (required)>' from <internal:/home/yahonda/.rbenv/versions/trunk/lib/ruby/3.3.0+0/rubygems/core_ext/kernel_require.rb>:37:in `require' from <internal:/home/yahonda/.rbenv/versions/trunk/lib/ruby/3.3.0+0/rubygems/core_ext/kernel_require.rb>:37:in `require' from /home/yahonda/src/github.com/rails/rails/activerecord/test/activejob/destroy_association_async_test.rb:11:in `<top (required)>' from <internal:/home/yahonda/.rbenv/versions/trunk/lib/ruby/3.3.0+0/rubygems/core_ext/kernel_require.rb>:37:in `require' from <internal:/home/yahonda/.rbenv/versions/trunk/lib/ruby/3.3.0+0/rubygems/core_ext/kernel_require.rb>:37:in `require' from /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:50:in `block in load_tests' from /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:50:in `each' from /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:50:in `load_tests' from /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:42:in `run' from /home/yahonda/src/github.com/rails/rails/activerecord/test/support/tools.rb:37:in `<top (required)>' from bin/test:11:in `require_relative' from bin/test:11:in `<main>' $ ``` -- https://bugs.ruby-lang.org/
2 3
0 0
[ruby-core:111956] [Ruby master Bug#19363] Fix rb_transient_heap_mark: wrong header (T_STRUCT) segfault
by bkuhlmann (Brooke Kuhlmann) 10 Apr '23

10 Apr '23
Issue #19363 has been reported by bkuhlmann (Brooke Kuhlmann). ---------------------------------------- Bug #19363: Fix rb_transient_heap_mark: wrong header (T_STRUCT) segfault https://bugs.ruby-lang.org/issues/19363 * Author: bkuhlmann (Brooke Kuhlmann) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) +YJIT [arm64-darwin22.2.0] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ## Overview Hello. 👋 I'm hitting an issue where my build is constantly failing with a segfault. The following is a snippet taken from my local machine with YJIT enabled (see attachments for details): ``` /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/puma-6.0.2/lib/puma/runner.rb: [BUG] rb_transient_heap_mark: wrong header, T_STRUCT (0x0000000109ea98a0) ruby 3.2.0 (2022-12-25 revision a528908271) +YJIT [arm64-darwin22.2.0] ``` The closest issue I could find that might be related to this issue (but not sure) is this issue: #15358. ## Steps to Recreate You should be able to quickly recreate this issue via these steps: - Download/clone my [Hemo](https://github.com/bkuhlmann/hemo) project. - Run the setup steps. - Run the test suite by running `bin/rspec`. If you need an example of the same segfault (but not on my macOS machine), you can see the same segfault via my [Circle CI Build](https://app.circleci.com/pipelines/github/bkuhlmann/hemo/11/workflow…. My Circle CI build is using my [Docker Alpine Linux Ruby](https://www.alchemists.io/projects/docker-alpine-ruby) image which might be of interest as well. This Docker image is also built with YJIT enabled. Interestingly, is if you were to run the test suite with `bin/guard` instead of `bin/rspec` then the segfault doesn't occur. ## Environment ``` ruby 3.2.0 (2022-12-25 revision a528908271) +YJIT [arm64-darwin22.2.0] 1.43.0 (using Parser 3.2.0.0, rubocop-ast 1.24.1, running on ruby 3.2.0) [arm64-darwin22.2.0] - rubocop-performance 1.15.2 - rubocop-rake 0.6.0 - rubocop-rspec 2.18.1 - rubocop-sequel 0.3.4 - rubocop-thread_safety 0.4.4 ``` ---Files-------------------------------- segfault.txt (237 KB) ruby-2023-01-21-113841.ips (19.6 KB) -- https://bugs.ruby-lang.org/
6 8
0 0
[ruby-core:113087] [Ruby master Bug#19570] `Exception#full_message` raises an `EncodingError` if the exception contains UTF8 characters after a newline and `Exception#cause` contains UTF8 characters
by timothy.willard (Timothy Willard) 10 Apr '23

10 Apr '23
Issue #19570 has been reported by timothy.willard (Timothy Willard). ---------------------------------------- Bug #19570: `Exception#full_message` raises an `EncodingError` if the exception contains UTF8 characters after a newline and `Exception#cause` contains UTF8 characters https://bugs.ruby-lang.org/issues/19570 * Author: timothy.willard (Timothy Willard) * Status: Open * Priority: Normal * ruby -v: 3.2.1 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ``` e = begin begin raise "Übersicht" rescue => e raise "\n#{e.message}" end rescue => e e end e.full_message ``` will reproduce the error with the exception `incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)`. In this case, all of `e.message`, `e.cause.message` and `e.cause.detailed_message` have a UTF-8 encoding, but `e.detailed_message` has an ASCII-8BIT encoding. I think the issue is related to [this](https://github.com/ruby/ruby/blob/31819e82c88c6f8ecfaeb162519bfa26a14… line (possibly caused by the encoding differences between `write_warn2` used [here](https://github.com/ruby/ruby/blob/31819e82c88c6f8ecfaeb162519bfa26a14… and [here](https://github.com/ruby/ruby/blob/31819e82c88c6f8ecfaeb162519bfa26a14… in the newline case vs `write_warn_str` used [here](https://github.com/ruby/ruby/blob/31819e82c88c6f8ecfaeb162519bfa26a14… in the no-newline case. -- https://bugs.ruby-lang.org/
2 1
0 0
[ruby-core:113161] AIX 64-bit Ruby 2.5.9 build's miniruby hangs
by Jay Mav 08 Apr '23

08 Apr '23
Hello, Building 64-bit Ruby 2.5.9 on AIX using xlc compiler. Miniruby hangs during "generating encdb.h". Call-stacks of the miniruby process: ---------- tid# 24838655 (pthread ID: 1) ---------- 0x00000001001267f0 ruby_atomic_compare_and_swap(0x1100636b8, 0x1b15a7001b15a7, 0x1af5a7001af5a7) + 0x30 0x000000010001c058 atomic_sub_nounderflow(0x1100636b8, 0x2000) + 0x58 0x0000000100025880 objspace_malloc_increase(0x1100636b0, 0x1102f8f30, 0x0, 0x2000, 0x200000002) + 0x80 0x000000010001eb8c objspace_xfree(0x1100636b0, 0x1102f8f30, 0x2000) + 0x4c 0x000000010001ec10 ruby_sized_xfree(0x1102f8f30, 0x2000) + 0x30 0x00000001001e71a4 free_io_buffer(0x1102f8e90) + 0x24 0x00000001001e7394 fptr_finalize(0x1102f8e50, 0x0) + 0x34 0x00000001001e7438 rb_io_fptr_cleanup(0x1102f8e50, 0x0) + 0x58 0x00000001001e7560 io_close_fptr(0x1101ad7c0) + 0xe0 0x00000001001e7674 rb_io_close(0x1101ad7c0) + 0x14 0x0000000100007378 restore_load_file(0xfffffffffffe900) + 0x38 0x00000001000083dc rb_ensure(0x110023278, 0xfffffffffffe900, 0x110023290, 0xfffffffffffe900) + 0x1bc 0x00000001000009a0 load_file(0x1101ae468, 0x1101ae698, 0x1101ad7c0, 0x100000001, 0xfffffffffffefb0) + 0x60 0x0000000100005688 process_options(0x60000000b, 0xffffffffffff4c8, 0xfffffffffffefb0) + 0xa48 0x0000000100005c50 ruby_process_options(0xb0000000b, 0xffffffffffff4a0) + 0xd0 0x000000010000be70 ruby_options(0xb0000000b, 0xffffffffffff4a0) + 0xd0 0x0000000100000560 main(0xb0000000b, 0xffffffffffff4a0) + 0x60 0x0000000100000268 __start() + 0x70 ---------- tid# 21168597 (pthread ID: 258) ---------- 0x0900000000168334 __fd_poll(??, ??, ??) + 0xb4 0x000000010011d6c4 poll(0x1102dc6d8, 0x2, 0xffffffffffffffff) + 0x24 0x000000010011d790 timer_thread_sleep(0x110062678) + 0x90 0x000000010011d944 thread_timer(0x110062678) + 0x44 0x09000000005abfe8 _pthread_body(??) + 0xe8 Any suggestions on how to fix this? Thanks.
1 0
0 0
[ruby-core:113147] [Ruby master Bug#19583] Unary minus inconsistency when used with variables and literals
by hurricup (Alexandr Evstigneev) 06 Apr '23

06 Apr '23
Issue #19583 has been reported by hurricup (Alexandr Evstigneev). ---------------------------------------- Bug #19583: Unary minus inconsistency when used with variables and literals https://bugs.ruby-lang.org/issues/19583 * Author: hurricup (Alexandr Evstigneev) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- This feels a bit inconsistent and I could not find an explanation. This is fine and `-` has higher precedence than `.` ``` -2.upto 0 do |arg| puts arg end ``` But this is not working, won't even compile (requires parens): ``` var = 2 -var.upto 0 do |arg| puts arg end ``` I presume that in the first example there is no unary minus operation, just negative literal. -- https://bugs.ruby-lang.org/
3 2
0 0
[ruby-core:113138] [Ruby master Misc#19581] Will Openssl 1.1.x fully support for Ruby3.1 throught the life time of Ruby3.1?
by mliu404 (Nikola Liu) 06 Apr '23

06 Apr '23
Issue #19581 has been reported by mliu404 (Nikola Liu). ---------------------------------------- Misc #19581: Will Openssl 1.1.x fully support for Ruby3.1 throught the life time of Ruby3.1? https://bugs.ruby-lang.org/issues/19581 * Author: mliu404 (Nikola Liu) * Status: Open * Priority: Normal ---------------------------------------- Currently Ruby3.1 require openSSL 1.1.x / 3.0.x to build rubyGem. Does the requirement for openSSL will be the same for all future minor version of Ruby3.1 ? -- https://bugs.ruby-lang.org/
2 1
0 0
[ruby-core:113132] [Ruby master Feature#18368] Range#step semantics for non-Numeric ranges
by Dan0042 (Daniel DeLorme) 05 Apr '23

05 Apr '23
Issue #18368 has been updated by Dan0042 (Daniel DeLorme). Ah, from https://github.com/ruby/dev-meeting-log/blob/master/2022/DevMeeting-2022-01… > matz: we should not modify the behavior when the receiver is a String I take that to mean Matz prefers not breaking compatibility. ---------------------------------------- Feature #18368: Range#step semantics for non-Numeric ranges https://bugs.ruby-lang.org/issues/18368#change-102666 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal ---------------------------------------- I am sorry if the question had already been discussed, can't find the relevant topic. "Intuitively", this looks (for me) like a meaningful statement: ```ruby (Time.parse('2021-12-01')..Time.parse('2021-12-24')).step(1.day).to_a # ^^^^^ or just 24*60*60 ``` Unfortunately, it doesn't work with "TypeError (can't iterate from Time)". Initially it looked like a bug for me, but after digging a bit into code/docs, I understood that `Range#step` has an odd semantics of "advance the begin N times with `#succ`, and yield the result", with N being always integer: ```ruby ('a'..'z').step(3).first(5) # => ["a", "d", "g", "j", "m"] ``` The fact that semantic is "odd" is confirmed by the fact that for Float it is redefined to do what I "intuitively" expected: ```ruby (1.0..7.0).step(0.3).first(5) # => [1.0, 1.3, 1.6, 1.9, 2.2] ``` (Like with [`Range#===` some time ago](https://bugs.ruby-lang.org/issues/14575), I believe that to be a strong proof of the wrong generic semantics, if for numbers the semantics needed to be redefined completely.) Another thing to note is that "skip N elements" seem to be rather "generically Enumerable-related" yet it isn't defined on `Enumerable` (because nobody needs this semantics, typically!) Hence, two questions: * Can we redefine generic `Range#step` to new semantics (of using `begin + step` iteratively)? It is hard to imagine the amount of actual usage of the old behavior (with String?.. to what end?) in the wild * If the answer is "no", can we define a new method with new semantics, like, IDK, `Range#over(span)`? **UPD:** More examples of useful behavior (it is NOT only about core `Time` class): ```ruby require 'active_support/all' (1.minute..20.minutes).step(2.minutes).to_a #=> [1 minute, 3 minutes, 5 minutes, 7 minutes, 9 minutes, 11 minutes, 13 minutes, 15 minutes, 17 minutes, 19 minutes] require 'tod' (Tod::TimeOfDay.parse("8am")..Tod::TimeOfDay.parse("10am")).step(30.minutes).to_a #=> [#<Tod::TimeOfDay 08:00:00>, #<Tod::TimeOfDay 08:30:00>, #<Tod::TimeOfDay 09:00:00>, #<Tod::TimeOfDay 09:30:00>, #<Tod::TimeOfDay 10:00:00>] require 'matrix' (Vector[1, 2, 3]..).step(Vector[1, 1, 1]).take(3) #=> [Vector[1, 2, 3], Vector[2, 3, 4], Vector[3, 4, 5]] require 'unitwise' (Unitwise(0, 'km')..Unitwise(1, 'km')).step(Unitwise(100, 'm')).map(&:to_s) #=> ["0 km", "1/10 km", "1/5 km", "3/10 km", "2/5 km", "0.5 km", "3/5 km", "7/10 km", "4/5 km", "9/10 km", "1 km"] ``` **UPD:** Responding to discussion points: **Q:** Matz is concerned that the proposed simple definition will be confusing with the classes where `+` is redefined as concatenation. **A:** I believe that simplicity of semantics and ease of explaining ("it just uses `+` underneath, whatever `+` does, will be performed") will make the confusion minimal. **Q:** Why not introduce new API requirement (like "class of range's `begin` should implement `increment` method, and then it will be used in `step`) **A:** require *every* gem author to change *every* of their objects' behavior. For that, they should be aware of the change, consider it important enough to care, clearly understand the necessary semantics of implementation, have a resource to release a new version... Then all users of all such gems would be required to upgrade. The feature would be DOA (dead-on-arrival). The two alternative ways I am suggesting: change the behavior of `#step` or introduce a new method with desired behavior: 1. Easy to explain and announce 2. Require no other code changes to immediately become useful 3. With something like [backports](https://github.com/marcandre/backports) or [ruby-next](https://github.com/ruby-next/ruby-next) easy to start using even in older Ruby version, making the code more expressive even before it would be possible for some particular app/compny to upgrade to (say) 3.2 All examples of behavior from the code above are real `irb` output with monkey-patched `Range#step`, demonstrating how little change will be needed to code outside of the `Range`. -- https://bugs.ruby-lang.org/
1 0
0 0
[ruby-core:113131] [Ruby master Feature#18368] Range#step semantics for non-Numeric ranges
by zverok (Victor Shepelev) 05 Apr '23

05 Apr '23
Issue #18368 has been updated by zverok (Victor Shepelev). @Dan0042 I value backwards compatibility a lot (I mentioned it in original ticket). I though believe that in _this_ particular case the old behaviour for non-numeric ranges is so weird that 1. Very small amount of code, if any, would be broken 2. The error would be very clear 3. Preserving both behaviours just for strings would be very hard to explain in hindsight and will affect language's quality and learnability. ---------------------------------------- Feature #18368: Range#step semantics for non-Numeric ranges https://bugs.ruby-lang.org/issues/18368#change-102665 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal ---------------------------------------- I am sorry if the question had already been discussed, can't find the relevant topic. "Intuitively", this looks (for me) like a meaningful statement: ```ruby (Time.parse('2021-12-01')..Time.parse('2021-12-24')).step(1.day).to_a # ^^^^^ or just 24*60*60 ``` Unfortunately, it doesn't work with "TypeError (can't iterate from Time)". Initially it looked like a bug for me, but after digging a bit into code/docs, I understood that `Range#step` has an odd semantics of "advance the begin N times with `#succ`, and yield the result", with N being always integer: ```ruby ('a'..'z').step(3).first(5) # => ["a", "d", "g", "j", "m"] ``` The fact that semantic is "odd" is confirmed by the fact that for Float it is redefined to do what I "intuitively" expected: ```ruby (1.0..7.0).step(0.3).first(5) # => [1.0, 1.3, 1.6, 1.9, 2.2] ``` (Like with [`Range#===` some time ago](https://bugs.ruby-lang.org/issues/14575), I believe that to be a strong proof of the wrong generic semantics, if for numbers the semantics needed to be redefined completely.) Another thing to note is that "skip N elements" seem to be rather "generically Enumerable-related" yet it isn't defined on `Enumerable` (because nobody needs this semantics, typically!) Hence, two questions: * Can we redefine generic `Range#step` to new semantics (of using `begin + step` iteratively)? It is hard to imagine the amount of actual usage of the old behavior (with String?.. to what end?) in the wild * If the answer is "no", can we define a new method with new semantics, like, IDK, `Range#over(span)`? **UPD:** More examples of useful behavior (it is NOT only about core `Time` class): ```ruby require 'active_support/all' (1.minute..20.minutes).step(2.minutes).to_a #=> [1 minute, 3 minutes, 5 minutes, 7 minutes, 9 minutes, 11 minutes, 13 minutes, 15 minutes, 17 minutes, 19 minutes] require 'tod' (Tod::TimeOfDay.parse("8am")..Tod::TimeOfDay.parse("10am")).step(30.minutes).to_a #=> [#<Tod::TimeOfDay 08:00:00>, #<Tod::TimeOfDay 08:30:00>, #<Tod::TimeOfDay 09:00:00>, #<Tod::TimeOfDay 09:30:00>, #<Tod::TimeOfDay 10:00:00>] require 'matrix' (Vector[1, 2, 3]..).step(Vector[1, 1, 1]).take(3) #=> [Vector[1, 2, 3], Vector[2, 3, 4], Vector[3, 4, 5]] require 'unitwise' (Unitwise(0, 'km')..Unitwise(1, 'km')).step(Unitwise(100, 'm')).map(&:to_s) #=> ["0 km", "1/10 km", "1/5 km", "3/10 km", "2/5 km", "0.5 km", "3/5 km", "7/10 km", "4/5 km", "9/10 km", "1 km"] ``` **UPD:** Responding to discussion points: **Q:** Matz is concerned that the proposed simple definition will be confusing with the classes where `+` is redefined as concatenation. **A:** I believe that simplicity of semantics and ease of explaining ("it just uses `+` underneath, whatever `+` does, will be performed") will make the confusion minimal. **Q:** Why not introduce new API requirement (like "class of range's `begin` should implement `increment` method, and then it will be used in `step`) **A:** require *every* gem author to change *every* of their objects' behavior. For that, they should be aware of the change, consider it important enough to care, clearly understand the necessary semantics of implementation, have a resource to release a new version... Then all users of all such gems would be required to upgrade. The feature would be DOA (dead-on-arrival). The two alternative ways I am suggesting: change the behavior of `#step` or introduce a new method with desired behavior: 1. Easy to explain and announce 2. Require no other code changes to immediately become useful 3. With something like [backports](https://github.com/marcandre/backports) or [ruby-next](https://github.com/ruby-next/ruby-next) easy to start using even in older Ruby version, making the code more expressive even before it would be possible for some particular app/compny to upgrade to (say) 3.2 All examples of behavior from the code above are real `irb` output with monkey-patched `Range#step`, demonstrating how little change will be needed to code outside of the `Range`. -- https://bugs.ruby-lang.org/
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • ...
  • 331
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.