The evolution of Ruby's Range class
The article details the Ruby Range class's evolution, its uses in programming, comparisons with other languages, and key updates, including endless ranges and methods for value testing and iteration.
Read original articleThe article discusses the evolution and design of the Ruby Range class, emphasizing its significance in programming. A Range in Ruby is defined by two boundaries and can represent both discrete and continuous values. The article outlines the main uses of ranges, including iteration, value testing, and collection slicing, and compares Ruby's implementation with other programming languages like Python, C#, Rust, Kotlin, and Scala.
The history of Ruby's versions is traced, highlighting key changes in the Range class from its inception in 1996 to the latest updates in Ruby 3.3. The article explains how methods like #include? and #cover? were developed to check if a value belongs to a range, with #=== being used in pattern matching. Notably, Ruby 2.6 saw a change where #=== was modified to use #cover? for consistency.
The article also touches on the types of values that can serve as range boundaries, noting that they must be comparable. It introduces the concept of "endless" ranges, which were added in Ruby 2.6, allowing for ranges that extend indefinitely. The discussion concludes with examples of how ranges can be utilized in various contexts, including array slicing and conditional statements, showcasing their versatility in Ruby programming.
Related
Ruby: A great language for shell scripts
Ruby is praised for shell scripting due to its features like calling external commands, handling status codes, using types, functional constructs, regex matching, threading, and file operations. It's recommended for complex scripts alongside Bash.
JRuby funding at Red Hat stopped – call for sponsors
JRuby gains independence post Red Hat sponsorship end. Updates 9.3.15.0 and 9.4.8.0 released, with plans for JRuby 10 supporting Ruby 3.4 and Rails 7.1. Community urged for GitHub sponsorship or commercial support for continued development.
Go Range Iterators Demystified
The Go 1.23 release introduces range iterators for custom collection types, offering flexibility for iteration beyond maps and slices. These iterators support various loop forms and enable powerful iteration scenarios.
First impressions of Go 1.23's range-over-func feature
The author shares positive experiences with Go 1.23's range-over-func feature, initially skeptical but finding it easy to use. Successful adaptation in their project Kivik disproved initial concerns, highlighting benefits for codebase improvement.
Top Ruby Companies Around the World
The article highlights 51 public companies using Ruby, with a combined market cap of $361 billion and revenue of $66.7 billion, including notable firms like Airbnb and Shopify.
I guess this isn't super constructive, but to me the whole thing smells of not just a lack of discipline, but a lack of _interest_ in correctness that seems to be endemic in the Ruby community.
We ended up writing our own `TimeRange` class to paper over the base Range bugs that show up if you use it with times.
One awkward takeaway from the experience is that I've come to believe that sometimes it _is_ worth unit testing other people's code, counter to the popular advice.
Can you predict the output of the following?
(1..20).each do |i|
puts i if i.odd?..i.prime?
end
Related
Ruby: A great language for shell scripts
Ruby is praised for shell scripting due to its features like calling external commands, handling status codes, using types, functional constructs, regex matching, threading, and file operations. It's recommended for complex scripts alongside Bash.
JRuby funding at Red Hat stopped – call for sponsors
JRuby gains independence post Red Hat sponsorship end. Updates 9.3.15.0 and 9.4.8.0 released, with plans for JRuby 10 supporting Ruby 3.4 and Rails 7.1. Community urged for GitHub sponsorship or commercial support for continued development.
Go Range Iterators Demystified
The Go 1.23 release introduces range iterators for custom collection types, offering flexibility for iteration beyond maps and slices. These iterators support various loop forms and enable powerful iteration scenarios.
First impressions of Go 1.23's range-over-func feature
The author shares positive experiences with Go 1.23's range-over-func feature, initially skeptical but finding it easy to use. Successful adaptation in their project Kivik disproved initial concerns, highlighting benefits for codebase improvement.
Top Ruby Companies Around the World
The article highlights 51 public companies using Ruby, with a combined market cap of $361 billion and revenue of $66.7 billion, including notable firms like Airbnb and Shopify.