Skip to content

Commit de09474

Browse files
authored
Translate "Ruby 3.4.0 preview2 Released" (zh_CN) (#3383)
1 parent 235860a commit de09474

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
layout: news_post
3+
title: "Ruby 3.4.0 preview2 已发布"
4+
author: "naruse"
5+
translator: "GAO Jun"
6+
date: 2024-10-07 00:00:00 +0000
7+
lang: zh_cn
8+
---
9+
10+
{% assign release = site.data.releases | where: "version", "3.4.0-preview2" | first %}
11+
我们很高兴地宣布 Ruby {{ release.version }} 发布。
12+
13+
## Prism
14+
15+
默认解析器由 parse.y 切换到 Prism。 [[Feature #20564]]
16+
17+
## 语言变化
18+
19+
* 在没有 `frozen_string_literal` 注释的文件中,当字符串字面量被修改时会发出警告。
20+
这些警告可以使用 `-W:deprecated` 或者通过设置 `Warning[:deprecated] = true` 来启用。
21+
如要禁用此变化,您可以在运行 Ruby 时,使用 `--disable-frozen-string-literal` 命令行参数。 [[Feature #20205]]
22+
23+
* 增加了 `it` 来引用块参数。 [[Feature #18980]]
24+
25+
* 支持在调用方法时使用 `nil` 作为关键字展开参数。
26+
`**nil` 类似于 `**{}`,不传递关键字参数,也不调用任何转换方法。 [[Bug #20064]]
27+
28+
* 索引不再接受块传递。 [[Bug #19918]]
29+
30+
* 索引不再接受关键字参数。 [[Bug #20218]]
31+
32+
## 核心类更新
33+
34+
注意:我们只列出了重要的类更新。
35+
36+
* Exception
37+
38+
* Exception#set_backtrace 现在接受 `Thread::Backtrace::Location` 数组。
39+
`Kernel#raise``Thread#raise``Fiber#raise` 也接受这个新格式。 [[Feature #13557]]
40+
41+
* Range
42+
43+
* 当 range 不可枚举时,Range#size 将抛出 TypeError。 [[Misc #18984]]
44+
45+
46+
47+
## 兼容性问题
48+
49+
注意:不包括问题补丁。
50+
51+
* 修改了错误信息和错误栈的显示。
52+
* 使用单引号(`'`)代替反勾号(`` ` ``)作为错误消息的起始引号。 [[Feature #16495]]
53+
* 在方法名前显示类名(仅当类具有永久名称时)。 [[Feature #19117]]
54+
* `Kernel#caller``Thread::Backtrace::Location` 等的方法也进行了相应更改。
55+
56+
```
57+
此前:
58+
test.rb:1:in `foo': undefined method `time' for an instance of Integer
59+
from test.rb:2:in `<main>'
60+
61+
现在:
62+
test.rb:1:in 'Object#foo': undefined method 'time' for an instance of Integer
63+
from test.rb:2:in `<main>'
64+
```
65+
66+
* `Hash#inspect` 显示格式发生变化 [[Bug #20433]]
67+
* 使用现代的表达语法来显示符号类型键值的情况: `"{user: 1}"`
68+
* 其他类型的键值在显示时,在 `=>` 前后增加空格: `'{"user" => 1}'`,此前的显示为: `'{"user"=>1}'`
69+
70+
## C API 更新
71+
72+
* 移除 `rb_newobj``rb_newobj_of` (以及相关的宏 `RB_NEWOBJ``RB_NEWOBJ_OF``NEWOBJ``NEWOBJ_OF`)。 [[Feature #20265]]
73+
* 移除废除的函数 `rb_gc_force_recycle`[[Feature #18290]]
74+
75+
## 实现改进
76+
77+
* `Array#each` 用 Ruby 重写,以提供更好的性能 [[Feature #20182]]
78+
79+
## 其他变化
80+
81+
* 如果传递了一个块给不使用块的方法时,在详细模式(`-w`)中将显示警告。 [[Feature #15554]]
82+
83+
* Ruby 对一些核心方法通过解释器和 JIT 进行了优化,诸如 `String.freeze``Integer#+`
84+
当这些方法被重定义时,解释器将发出性能警告(`-W:performance``Warning[:performance] = true`)。 [[Feature #20429]]
85+
86+
有关默认 gems 和 绑定 gems 的细节,可以参考 GitHub 上的发布,例如 [logger gem](https://github.com/ruby/logger/releases) 或相应的变更日志。
87+
[提交日志](https://github.com/ruby/ruby/compare/v3_3_0...{{ release.tag }})。
88+
89+
自 Ruby 3.3.0 以来,这些变化共导致 [{{ release.stats.files_changed }} 个文件被更改,新增 {{ release.stats.insertions }} 行(+),删除 {{ release.stats.deletions }} 行(-)](https://github.com/ruby/ruby/compare/v3_3_0...{{ release.tag }}#file_bucket)!
90+
91+
92+
## 下载
93+
94+
* <{{ release.url.gz }}>
95+
96+
文件大小: {{ release.size.gz }}
97+
SHA1: {{ release.sha1.gz }}
98+
SHA256: {{ release.sha256.gz }}
99+
SHA512: {{ release.sha512.gz }}
100+
101+
* <{{ release.url.xz }}>
102+
103+
文件大小: {{ release.size.xz }}
104+
SHA1: {{ release.sha1.xz }}
105+
SHA256: {{ release.sha256.xz }}
106+
SHA512: {{ release.sha512.xz }}
107+
108+
* <{{ release.url.zip }}>
109+
110+
文件大小: {{ release.size.zip }}
111+
SHA1: {{ release.sha1.zip }}
112+
SHA256: {{ release.sha256.zip }}
113+
SHA512: {{ release.sha512.zip }}
114+
115+
## Ruby 是什么
116+
117+
Ruby 最初由 Matz (松本行弘,Yukihiro Matsumoto) 于 1993 年开发,现在以开源软件的形式开发。它可以在多个平台上运行,并在全球得到广泛使用,尤其是 Web 开发领域。
118+
119+
[Feature #13557]: https://bugs.ruby-lang.org/issues/13557
120+
[Feature #15554]: https://bugs.ruby-lang.org/issues/15554
121+
[Feature #16495]: https://bugs.ruby-lang.org/issues/16495
122+
[Feature #18290]: https://bugs.ruby-lang.org/issues/18290
123+
[Feature #18980]: https://bugs.ruby-lang.org/issues/18980
124+
[Misc #18984]: https://bugs.ruby-lang.org/issues/18984
125+
[Feature #19117]: https://bugs.ruby-lang.org/issues/19117
126+
[Bug #19918]: https://bugs.ruby-lang.org/issues/19918
127+
[Bug #20064]: https://bugs.ruby-lang.org/issues/20064
128+
[Feature #20182]: https://bugs.ruby-lang.org/issues/20182
129+
[Feature #20205]: https://bugs.ruby-lang.org/issues/20205
130+
[Bug #20218]: https://bugs.ruby-lang.org/issues/20218
131+
[Feature #20265]: https://bugs.ruby-lang.org/issues/20265
132+
[Feature #20429]: https://bugs.ruby-lang.org/issues/20429
133+
[Feature #20564]: https://bugs.ruby-lang.org/issues/20564
134+
[Bug #20433]: https://bugs.ruby-lang.org/issues/20433

0 commit comments

Comments
 (0)