Skip to content

Commit 94914be

Browse files
authored
Merge pull request rurema#3341 from znz/version-range-adoption
版範囲の #%if を #%version 記法に置き換え (refs rurema/bitclust#285)
2 parents e7a21dc + b74a1f4 commit 94914be

17 files changed

Lines changed: 134 additions & 65 deletions

Gemfile.lock

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
GIT
2-
remote: https://github.com/rurema/bitclust.git
3-
revision: 3c9999411372b350a4ae0e55c2de669390cadc10
1+
PATH
2+
remote: ../bitclust
43
specs:
54
bitclust-core (1.5.0)
65
drb

docs/ReferenceManualFormatDigest.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,24 @@ Ruby 3.2 にはこの機能が含まれません 〜〜〜
295295
#%end
296296
```
297297

298+
### #%version
299+
300+
バージョン範囲(半開区間)にあてはまる文章を書くのに使います。
301+
`A...B` は「A 以上 B 未満」です(Ruby の終端排他 Range リテラルと同じ 3 点ドット。
302+
`..` は使えません)。`A...`(A 以上)、`...B`(B 未満)も書けます。
303+
304+
```
305+
#%version 3.1...3.4
306+
Ruby 3.1 以上 3.4 未満では 〜〜
307+
#%end
308+
```
309+
310+
`#%since` / `#%until` / `#%version` / `#%if``#%else` と組み合わせられます。
311+
298312
### #%if
299313

300314
Ruby の特定のバージョンにあてはまる文章を書くのに使います。条件には比較式のみ書けます。
315+
範囲の条件は `#%if` ではなく上の `#%version` で書いてください。
301316

302317
```
303318
#%if (version >= "3.1")

manual/api/_builtin/Module.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,13 +1300,13 @@ class Factory
13001300
private_class_method :foo
13011301
end
13021302

1303-
#%if("3.4" <= version)
1303+
#%version 3.4...
13041304
Factory.foo # NoMethodError: private method 'foo' called for class Factory
13051305
#%end
1306-
#%if("3.3" <= version and version < "3.4")
1306+
#%version 3.3...3.4
13071307
Factory.foo # NoMethodError: private method `foo' called for class Factory
13081308
#%end
1309-
#%if(version < "3.3")
1309+
#%version ...3.3
13101310
Factory.foo # NoMethodError: private method `foo' called for Factory:Class
13111311
#%end
13121312

@@ -1841,13 +1841,13 @@ end
18411841

18421842
account = Account.new
18431843
p account.foo1 # => 1
1844-
#%if("3.4" <= version)
1844+
#%version 3.4...
18451845
account.foo2 # => private method 'foo2' called for an instance of Account (NoMethodError)
18461846
#%end
1847-
#%if("3.3" <= version and version < "3.4")
1847+
#%version 3.3...3.4
18481848
account.foo2 # => private method `foo2' called for an instance of Account (NoMethodError)
18491849
#%end
1850-
#%if(version < "3.3")
1850+
#%version ...3.3
18511851
account.foo2 # => private method `foo2' called for #<Account:0x401b7628> (NoMethodError)
18521852
#%end
18531853
```
@@ -1902,13 +1902,13 @@ p foo # => 1
19021902
# the toplevel default is private
19031903
# (Ruby 2.7 以降、レシーバが self そのものの呼び出しは private でも可能なため
19041904
# self.foo はエラーにならない。別のオブジェクトをレシーバにすると呼び出せない)
1905-
#%if("3.4" <= version)
1905+
#%version 3.4...
19061906
Object.new.foo # => private method 'foo' called for an instance of Object (NoMethodError)
19071907
#%end
1908-
#%if("3.3" <= version and version < "3.4")
1908+
#%version 3.3...3.4
19091909
Object.new.foo # => private method `foo' called for an instance of Object (NoMethodError)
19101910
#%end
1911-
#%if(version < "3.3")
1911+
#%version ...3.3
19121912
Object.new.foo # => private method `foo' called for #<Object:0x401c83b0> (NoMethodError)
19131913
#%end
19141914

manual/api/_builtin/NameError.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ library: _builtin
77

88
```ruby title="例"
99
bar
10-
#%if("3.4" <= version)
10+
#%version 3.4...
1111
# ~> NameError: undefined local variable or method 'bar' for main
1212
#%end
13-
#%if("3.3" <= version and version < "3.4")
13+
#%version 3.3...3.4
1414
# ~> NameError: undefined local variable or method `bar' for main
1515
#%end
16-
#%if(version < "3.3")
16+
#%version ...3.3
1717
# ~> NameError: undefined local variable or method `bar' for main:Object
1818
#%end
1919
```
@@ -51,13 +51,13 @@ p err.name # => "foo"
5151
begin
5252
foobar
5353
rescue NameError => err
54-
#%if("3.4" <= version)
54+
#%version 3.4...
5555
p err # => #<NameError: undefined local variable or method 'foobar' for main>
5656
#%end
57-
#%if("3.3" <= version and version < "3.4")
57+
#%version 3.3...3.4
5858
p err # => #<NameError: undefined local variable or method `foobar' for main>
5959
#%end
60-
#%if(version < "3.3")
60+
#%version ...3.3
6161
p err # => #<NameError: undefined local variable or method `foobar' for main:Object>
6262
#%end
6363
p err.name # => :foobar
@@ -72,15 +72,15 @@ end
7272
begin
7373
foobar
7474
rescue NameError => err
75-
#%if("3.4" <= version)
75+
#%version 3.4...
7676
p err # => #<NameError: undefined local variable or method 'foobar' for main>
7777
p err.to_s # => "undefined local variable or method 'foobar' for main"
7878
#%end
79-
#%if("3.3" <= version and version < "3.4")
79+
#%version 3.3...3.4
8080
p err # => #<NameError: undefined local variable or method `foobar' for main>
8181
p err.to_s # => "undefined local variable or method `foobar' for main"
8282
#%end
83-
#%if(version < "3.3")
83+
#%version ...3.3
8484
p err # => #<NameError: undefined local variable or method `foobar' for main:Object>
8585
p err.to_s # => "undefined local variable or method `foobar' for main:Object"
8686
#%end

manual/api/_builtin/NoMethodError.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ library: _builtin
77

88
```ruby title="例"
99
self.bar
10-
#%if("3.4" <= version)
10+
#%version 3.4...
1111
# => -:1: undefined method 'bar' for main (NoMethodError)
1212
#%end
13-
#%if("3.3" <= version and version < "3.4")
13+
#%version 3.3...3.4
1414
# => -:1: undefined method `bar' for main (NoMethodError)
1515
#%end
16-
#%if(version < "3.3")
16+
#%version ...3.3
1717
# => -:1: undefined method `bar' for main:Object (NoMethodError)
1818
#%end
1919
```
@@ -22,13 +22,13 @@ self.bar
2222

2323
```ruby title="例"
2424
"".puts
25-
#%if("3.4" <= version)
25+
#%version 3.4...
2626
# => -:1:in '<main>': private method 'puts' called for an instance of String (NoMethodError)
2727
#%end
28-
#%if("3.3" <= version and version < "3.4")
28+
#%version 3.3...3.4
2929
# => -:1:in `<main>': private method `puts' called for an instance of String (NoMethodError)
3030
#%end
31-
#%if(version < "3.3")
31+
#%version ...3.3
3232
# => -:1:in `<main>': private method `puts' called for "":String (NoMethodError)
3333
#%end
3434
```
@@ -37,13 +37,13 @@ self.bar
3737

3838
```ruby title="例"
3939
bar
40-
#%if("3.4" <= version)
40+
#%version 3.4...
4141
# => -:1: undefined local variable or method 'bar' for main (NameError)
4242
#%end
43-
#%if("3.3" <= version and version < "3.4")
43+
#%version 3.3...3.4
4444
# => -:1: undefined local variable or method `bar' for main (NameError)
4545
#%end
46-
#%if(version < "3.3")
46+
#%version ...3.3
4747
# => -:1: undefined local variable or method `bar' for main:Object (NameError)
4848
#%end
4949
```
@@ -88,13 +88,13 @@ rescue NoMethodError
8888
p $!.args
8989
end
9090

91-
#%if("3.4" <= version)
91+
#%version 3.4...
9292
# => #<NoMethodError: undefined method 'foobar' for main>
9393
#%end
94-
#%if("3.3" <= version and version < "3.4")
94+
#%version 3.3...3.4
9595
# => #<NoMethodError: undefined method `foobar' for main>
9696
#%end
97-
#%if(version < "3.3")
97+
#%version ...3.3
9898
# => #<NoMethodError: undefined method `foobar' for main:Object>
9999
#%end
100100
# => :foobar

manual/api/_builtin/RubyVM__InstructionSequence.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ p RubyVM::InstructionSequence.compile_file("/tmp/hello.rb")
7979
命令シーケンスのコンパイル時のデフォルトの最適化オプションを Hash で返
8080
します。
8181

82-
#%if("3.4" <= version)
82+
#%version 3.4...
8383

8484
```ruby title="例"
8585
require "pp"
@@ -98,7 +98,7 @@ pp RubyVM::InstructionSequence.compile_option
9898
```
9999

100100
#%end
101-
#%if("3.3" <= version and version < "3.4")
101+
#%version 3.3...3.4
102102

103103
```ruby title="例"
104104
require "pp"
@@ -117,7 +117,7 @@ pp RubyVM::InstructionSequence.compile_option
117117
```
118118

119119
#%end
120-
#%if(version < "3.3")
120+
#%version ...3.3
121121

122122
```ruby title="例"
123123
require "pp"
@@ -158,7 +158,7 @@ options で指定します。
158158
* :operands_unification
159159
* :peephole_optimization
160160
* :specialized_instruction
161-
#%if(version < "3.3")
161+
#%version ...3.3
162162
* :stack_caching
163163
#%end
164164
* :tailcall_optimization

manual/api/_builtin/RubyVM__YJIT.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Ruby 3.2 で「実験的」の位置づけが外れ、Ruby 3.3 では実行時
3434
`RubyVM::ZJIT` という別のモジュールで提供されており、
3535
`RubyVM::YJIT` とは別物です。
3636

37-
#%if(version < "3.3")
37+
#%version ...3.3
3838
- **SEE** [c:RubyVM::MJIT]
3939
#%end
4040

@@ -80,13 +80,13 @@ JIT の有効・無効はコマンドラインオプションや環境変数な
8080
- **SEE** [m:RubyVM::YJIT.runtime_stats], [m:RubyVM::YJIT.stats_enabled?]
8181

8282
#%since 3.3
83-
#%if("4.0" <= version)
83+
#%version 4.0...
8484
### def enable(stats: false, log: false, mem_size: nil, call_threshold: nil) -> bool
8585
#%end
86-
#%if("3.4" <= version and version < "4.0")
86+
#%version 3.4...4.0
8787
### def enable(stats: false, log: false) -> bool
8888
#%end
89-
#%if(version < "3.4")
89+
#%version ...3.4
9090
### def enable(stats: false) -> bool
9191
#%end
9292

@@ -134,13 +134,13 @@ Marshal 形式で `filename` にダンプします。ダンプしたファイル
134134
#%#noexample 実行環境に依存するため
135135
#%end
136136

137-
#%if("3.4" <= version)
137+
#%version 3.4...
138138
### def runtime_stats(key = nil) -> Hash | object | nil
139139
#%end
140-
#%if("3.3" <= version and version < "3.4")
140+
#%version 3.3...3.4
141141
### def runtime_stats(context: false) -> Hash | nil
142142
#%end
143-
#%if(version < "3.3")
143+
#%version ...3.3
144144
### def runtime_stats -> Hash | nil
145145
#%end
146146

@@ -153,7 +153,7 @@ Marshal 形式で `filename` にダンプします。ダンプしたファイル
153153
対応する値を返します。統計収集が無効な場合は `nil` を返します。
154154
- **raise** `TypeError` -- `key` に Symbol 以外(`nil` を除く)を指定した場合に発生します。
155155
#%else
156-
#%if("3.3" <= version and version < "3.4")
156+
#%version 3.3...3.4
157157
- **param** `context` -- true を指定すると、コンパイルコンテキストに関する統計も含めます。
158158
#%end
159159
- **return** -- 統計情報のハッシュを返します。統計収集が無効な場合は `nil` を返します。

manual/api/did_you_mean.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ category: Development
77

88
```ruby
99
"Yuki".starts_with?("Y")
10-
#%if("3.4" <= version)
10+
#%version 3.4...
1111
# ~> NoMethodError: undefined method 'starts_with?' for an instance of String
1212
#%end
13-
#%if("3.3" <= version and version < "3.4")
13+
#%version 3.3...3.4
1414
# ~> NoMethodError: undefined method `starts_with?' for an instance of String
1515
#%end
16-
#%if(version < "3.3")
16+
#%version ...3.3
1717
# ~> NoMethodError: undefined method `starts_with?' for "Yuki":String
1818
#%end
1919
# Did you mean? start_with?

manual/api/singleton.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ end
3131
a = SomeSingletonClass.instance
3232
b = SomeSingletonClass.instance # a and b are same object
3333
p [a,b] # => [#<SomeSingletonClass:0x0000562e6e18ddd0>, #<SomeSingletonClass:0x0000562e6e18ddd0>]
34-
#%if("3.4" <= version)
34+
#%version 3.4...
3535
a = SomeSingletonClass.new # ~> NoMethodError: private method 'new' called for class SomeSingletonClass
3636
#%end
37-
#%if("3.3" <= version and version < "3.4")
37+
#%version 3.3...3.4
3838
a = SomeSingletonClass.new # ~> NoMethodError: private method `new' called for class SomeSingletonClass
3939
#%end
40-
#%if(version < "3.3")
40+
#%version ...3.3
4141
a = SomeSingletonClass.new # ~> NoMethodError: private method `new' called for SomeSingletonClass:Class
4242
#%end
4343
```

manual/api/socket/Socket.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,11 @@ sockets でサーバソケットを受け取り、接続を待ち受け、
413413

414414
ローカルの IP アドレスを配列で返します。
415415

416-
#%if("4.0" <= version)
416+
#%version 4.0...
417417
### def tcp(host, port, local_host=nil, local_port=nil, connect_timeout: nil, resolv_timeout: nil, open_timeout: nil, fast_fallback: true) -> Socket
418418
### def tcp(host, port, local_host=nil, local_port=nil, connect_timeout: nil, resolv_timeout: nil, open_timeout: nil, fast_fallback: true) {|socket| ... } -> object
419419
#%end
420-
#%if("3.4" <= version and version < "4.0")
420+
#%version 3.4...4.0
421421
### def tcp(host, port, local_host=nil, local_port=nil, connect_timeout: nil, resolv_timeout: nil, fast_fallback: true) -> Socket
422422
### def tcp(host, port, local_host=nil, local_port=nil, connect_timeout: nil, resolv_timeout: nil, fast_fallback: true) {|socket| ... } -> object
423423
#%end
@@ -438,10 +438,10 @@ local_host や local_port を指定した場合、ソケットをそこにバイ
438438
- **param** `local_port` -- 接続元のポート番号
439439
- **param** `connect_timeout` -- 接続確立のタイムアウトを秒数で指定します。
440440
- **param** `resolv_timeout` -- 名前解決のタイムアウトを秒数で指定します。
441-
#%if (version >= "4.0")
441+
#%version 4.0...
442442
- **param** `open_timeout` -- 名前解決から接続確立までのタイムアウトを秒数で指定します。
443443
#%end
444-
#%if (version >= "3.4")
444+
#%version 3.4...
445445
- **param** `fast_fallback` -- Happy Eyeballs Version 2 ([RFC 8305](https://datatracker.ietf.org/doc/html/rfc8305)) を有効にします。
446446
#%end
447447
- **return** -- ブロック付きで呼ばれた場合はブロックが返した値です。

0 commit comments

Comments
 (0)