[#115244] [Ruby master Feature#19987] add sample method to Range — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19987 has been reported by horv77@protonmail.com (Andras Horvath).
6 messages
2023/11/05
[#115247] [Ruby master Feature#19988] AI for inner code behavior analysis at runtime — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19988 has been reported by horv77@protonmail.com (Andras Horvath).
3 messages
2023/11/05
[#115404] Ruby 3.2.2 - rbconfig.rb's MAKEFILE_CONFIG — Jay Mav via ruby-core <ruby-core@...>
Hello Ruby Dev Team,
4 messages
2023/11/17
[ruby-core:115526] [Ruby master Feature#20027] Add Range Deconstruction
From:
"stuyam (Stuart Yamartino) via ruby-core" <ruby-core@...>
Date:
2023-11-28 20:20:22 UTC
List:
ruby-core #115526
Issue #20027 has been updated by stuyam (Stuart Yamartino). Subject changed from Range Deconstruction to Add Range Deconstruction Update title ---------------------------------------- Feature #20027: Add Range Deconstruction https://bugs.ruby-lang.org/issues/20027#change-105456 * Author: stuyam (Stuart Yamartino) * Status: Open * Priority: Normal ---------------------------------------- Ranges are a powerful tool in ruby. A common range I use is a date range such as `(Date.yesterday..Date.tomorrow)`. A range will often be passed around to methods because the dates hold meaning together such as a timeframe for a table filter. Often I want to grab the original values out of a range like: ```ruby timeframe = (Date.yesterday..Date.tomorrow) start_date = timeframe.begin end_date = timeframe.end #=> start_date = yesterday #=> end_date = today ``` Similar to array and hash deconstruction I thought it would be useful to support range deconstruction like this: ```ruby start_date, end_date = (Date.yesterday..Date.tomorrow) #=> start_date = yesterday #=> end_date = today ``` This would also work for endless or beginless ranges since the beginning and end are just nil in those cases: ```ruby start_date, end_day = ..Date.tomorrow #=> start_date = nil #=> end_date = tomorrow ``` You could do this now using `to_a` like: ```ruby start_date, *middle_dates, end_date = (Date.new(2000,1,1)..Date.new(2023,1,1).to_a ``` However this has unnecessary performance issues by converting the range to an array especially if the range spans a large period, `middle_dates` would hold a very large array. Also if the range resulted in an array with 2 values, `end_date` would be nil and this wouldn't actually work to get the begin and end values. I think this provides a simple interface for a common pattern of deconstructing ranges into their beginning and end values. It would be useful for ranges regardless of date ranges or other types of ranges since they are essentially tuples. Would love to know what others think about this <3 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/