Ruby 3.4 中有什么新内容

  • Ruby 3.4 was released on December 25, 2024.
  • Language changes:

    • Frozen string literals: By default, strings act as if frozen. Modifying a frozen string in a file with the magic comment will result in a deprecation warning instead of an error. A future version will raise an exception.
    • Default block parameter: Ruby 3.4 introduces a default block parameter to make short code blocks cleaner. Instead of using numbered parameters or naming them, you can use a simple name like it.
    • Keyword splatting nil: In Ruby 3.4, ** with nil implicitly converts nil into a hash.
  • Core classes updates:

    • Exception#set_backtrace: In Ruby 3.4, Exception#set_backtrace accepts a Thread::Backtrace::Location array to rebuild a Backtrace instance.
    • Range#size: If the range is not iterable, Ruby 3.4 will throw a TypeError when calling size.
  • Other changes:

    • Methods passing unused blocks: In verbose mode, Ruby will throw a warning if a block is passed to a method that doesn't use it.
    • Array.each performance improvement: Ruby 3.4 improves the performance of Array.each due to an implementation rewrite.
    • Error message and backtrace display update: Ruby will use single quotes instead of backticks and display a class name before a method name.
  • Upgrading to Ruby 3.4: Removing unneeded frozen string magic comments is the most labor-intensive part. Upgrading takes advantage of new features.
  • More articles: There are various articles related to Ruby, including managing PostgreSQL table partitioning, Rails and No PaaS, Ruby regex tricks, using Pry to debug, UUIDs and ULIDs, Rails load testing in Apache JMeter, using Solid Cache, comparing Go vs Ruby, Rails async queries, and Honeybadger's migration from Sidekiq to Karafka.
阅读 9
0 条评论