Skip to content

Commit f5f479d

Browse files
committed
docs: update keyword args syntax from **{ } to { }
- Changed keyword argument syntax: **{ x: Type } → { x: Type } - Added Hash literal syntax: config: { x: Type } - Fixed positional arg calls: build_query(table: "x") → build_query("x") - Fixed splat param types: *args: String → *args: Array<String> - Updated English, Korean, and Japanese docs
1 parent b8cfd52 commit f5f479d

File tree

9 files changed

+102
-66
lines changed

9 files changed

+102
-66
lines changed

docs/learn/functions/optional-rest-parameters.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,28 @@ team3 = create_team("Gamma", "Charlie", true, "Dave", "Eve", "Frank")
130130

131131
## Keyword Arguments
132132

133-
In T-Ruby, keyword arguments are defined using the `**{ }` syntax. Unlike positional arguments, they are passed by name when calling.
133+
In T-Ruby, keyword arguments are defined using the `{ }` syntax (without variable name). Unlike positional arguments, they are passed by name when calling.
134134

135135
:::info Positional vs Keyword Arguments
136136

137137
| Definition | Call Style |
138138
|------------|------------|
139139
| `(x: String, y: Integer)` | `foo("hi", 10)` - positional |
140-
| `(**{ x: String, y: Integer })` | `foo(x: "hi", y: 10)` - keyword |
140+
| `({ x: String, y: Integer })` | `foo(x: "hi", y: 10)` - keyword |
141+
| `(config: { x: String })` | `foo(config: { x: "hi" })` - Hash literal |
142+
143+
**Key Rule**: Variable name presence determines the meaning:
144+
- `{ ... }` (no variable) → keyword arguments (destructured)
145+
- `name: { ... }` (with variable) → Hash literal
141146

142147
:::
143148

144149
### Inline Type Style
145150

146-
Define types directly inside `**{ }`. Default values use `= value` syntax:
151+
Define types directly inside `{ }`. Default values use `= value` syntax:
147152

148153
```trb title="keyword_inline.trb"
149-
def create_post(**{
154+
def create_post({
150155
title: String,
151156
content: String,
152157
published: Boolean = false,
@@ -186,7 +191,7 @@ interface PostOptions
186191
tags?: Array<String>
187192
end
188193
189-
def create_post(**{ title:, content:, published: false, tags: [] }: PostOptions): Post
194+
def create_post({ title:, content:, published: false, tags: [] }: PostOptions): Post
190195
Post.new(
191196
title: title,
192197
content: content,
@@ -203,7 +208,7 @@ post = create_post(title: "Hello", content: "World")
203208

204209
| Aspect | Inline Type | Interface Reference |
205210
|--------|-------------|---------------------|
206-
| Type definition | Inside `**{ }` | Separate interface |
211+
| Type definition | Inside `{ }` | Separate interface |
207212
| Default value syntax | `= value` | `: value` (no equals) |
208213
| Optional marking | Implied by default value | `?` suffix |
209214
| Reusability | Single method | Shared across methods |
@@ -226,14 +231,14 @@ def create_config(env: String, **options: Hash<Symbol, String | Integer | Boolea
226231
end
227232
228233
# Using keyword rest parameters
229-
query1 = build_query(table: "users", id: 123, active: 1)
234+
query1 = build_query("users", id: 123, active: 1)
230235
# "SELECT * FROM users WHERE id = 123 AND active = 1"
231236
232-
query2 = build_query(table: "posts", author_id: 5, published: 1, category: "tech")
237+
query2 = build_query("posts", author_id: 5, published: 1, category: "tech")
233238
# "SELECT * FROM posts WHERE author_id = 5 AND published = 1 AND category = tech"
234239
235240
config = create_config(
236-
env: "production",
241+
"production",
237242
debug: false,
238243
timeout: 30,
239244
host: "example.com"
@@ -247,7 +252,7 @@ The type annotation `**conditions: Hash<Symbol, String | Integer>` means "zero o
247252
Keyword arguments without default values are required:
248253

249254
```trb title="required_kwargs.trb"
250-
def register_user(**{
255+
def register_user({
251256
email: String,
252257
password: String,
253258
name: String = "Anonymous",
@@ -280,15 +285,15 @@ You can combine all parameter types, but they must follow this order:
280285
1. Required positional parameters
281286
2. Optional positional parameters
282287
3. Rest parameter (`*args`)
283-
4. Keyword arguments (`**{ ... }`)
288+
4. Keyword arguments (`{ ... }`)
284289
5. Keyword rest parameter (`**kwargs`)
285290

286291
```trb title="all_types.trb"
287292
def complex_function(
288293
required_pos: String, # 1. Required positional
289294
optional_pos: Integer = 0, # 2. Optional positional
290295
*rest_args: Array<String>, # 3. Rest parameter
291-
**{
296+
{
292297
required_kw: Boolean, # 4. Required keyword
293298
optional_kw: String = "default" # 5. Optional keyword
294299
},
@@ -339,7 +344,7 @@ class HTTPRequestBuilder
339344
end
340345
341346
# Keyword arguments (inline type)
342-
def request(**{
347+
def request({
343348
method: String,
344349
url: String,
345350
body: String? = nil,
@@ -481,7 +486,7 @@ logger.debug(
481486

482487
4. **Use rest parameters for collections**: When you expect a variable number of similar items, rest parameters are cleaner than array parameters.
483488

484-
5. **Type rest parameters appropriately**: `*args: String` is better than `*args: String | Integer` if you only expect strings.
489+
5. **Type rest parameters appropriately**: `*args: Array<String>` is better than `*args: Array<String | Integer>` if you only expect strings.
485490

486491
6. **Document complex signatures**: When combining many parameter types, add comments explaining the usage.
487492

@@ -490,7 +495,7 @@ logger.debug(
490495
### Builder Methods with Defaults (Keyword Arguments)
491496

492497
```trb title="builder_pattern.trb"
493-
def build_email(**{
498+
def build_email({
494499
to: String,
495500
subject: String,
496501
from: String = "[email protected]",
@@ -508,7 +513,7 @@ email = build_email(to: "[email protected]", subject: "Hello")
508513
### Variadic Factory Functions (Rest + Keyword Arguments)
509514

510515
```trb title="factory.trb"
511-
def create_users(*names: Array<String>, **{ role: String = "user" }): Array<User>
516+
def create_users(*names: Array<String>, { role: String = "user" }): Array<User>
512517
names.map { |name| User.new(name: name, role: role) }
513518
end
514519
@@ -538,12 +543,14 @@ Optional and rest parameters give your functions flexibility while maintaining t
538543
| `(x: Type)` | Positional argument | `foo("hi")` |
539544
| `(x: Type = default)` | Optional positional | `foo()` or `foo("hi")` |
540545
| `(*args: Array<Type>)` | Rest parameter | `foo("a", "b", "c")` |
541-
| `(**{ x: Type })` | Keyword argument | `foo(x: "hi")` |
546+
| `({ x: Type })` | Keyword argument | `foo(x: "hi")` |
547+
| `(config: { x: Type })` | Hash literal | `foo(config: { x: "hi" })` |
542548
| `(**kwargs: Hash<Symbol, Type>)` | Keyword rest | `foo(a: 1, b: 2)` |
543549

544550
**Key Points:**
545551
- **Positional arguments** `(x: Type)`: passed by order
546-
- **Keyword arguments** `(**{ x: Type })`: passed by name
552+
- **Keyword arguments** `({ x: Type })`: passed by name (no variable = destructured)
553+
- **Hash literal** `(config: { x: Type })`: with variable name = Hash
547554
- **Keyword rest** `(**kwargs: Hash<Symbol, Type>)`: collects arbitrary keyword arguments into a hash
548555
- T-Ruby ensures type safety for all parameter variations
549556

docs/reference/cheatsheet.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,20 @@ def greet(name: String, greeting: String = "Hello"): String
6060
end
6161
6262
# Rest parameters
63-
def sum(*numbers: Integer): Integer
63+
def sum(*numbers: Array<Integer>): Integer
6464
numbers.sum
6565
end
6666
67-
# Keyword arguments
68-
def create_user(name: String, email: String, age: Integer = 18): Hash
67+
# Keyword arguments (no variable = destructured)
68+
def create_user({ name: String, email: String, age: Integer = 18 }): Hash
6969
{ name: name, email: email, age: age }
7070
end
7171
72+
# Hash literal (with variable name)
73+
def process(config: { host: String, port: Integer }): String
74+
"#{config[:host]}:#{config[:port]}"
75+
end
76+
7277
# No return value
7378
def log(message: String): void
7479
puts message

docs/reference/stdlib-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
- `File.readlines(path: String): Array<String>`
4949
- `File.open(path: String, mode: String): File`
5050
- `File.open(path: String, mode: String, &block: Proc<File, void>): void`
51-
- `File.delete(*paths: String): Integer`
51+
- `File.delete(*paths: Array<String>): Integer`
5252
- `File.rename(old: String, new: String): Integer`
5353
- `File.size(path: String): Integer`
5454
- `File.directory?(path: String): Boolean`

i18n/ja/docusaurus-plugin-content-docs/current/learn/functions/optional-rest-parameters.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,28 @@ team3 = create_team("Gamma", "Charlie", true, "Dave", "Eve", "Frank")
130130

131131
## キーワード引数
132132

133-
T-Rubyでは、キーワード引数は `**{ }` 構文を使用して定義します。位置引数とは異なり、呼び出し時に名前で引数を渡します。
133+
T-Rubyでは、キーワード引数は `{ }` 構文(変数名なし)を使用して定義します。位置引数とは異なり、呼び出し時に名前で引数を渡します。
134134

135135
:::info 位置引数 vs キーワード引数
136136

137137
| 定義 | 呼び出し方法 |
138138
|------|-------------|
139139
| `(x: String, y: Integer)` | `foo("hi", 10)` - 位置引数 |
140-
| `(**{ x: String, y: Integer })` | `foo(x: "hi", y: 10)` - キーワード引数 |
140+
| `({ x: String, y: Integer })` | `foo(x: "hi", y: 10)` - キーワード引数 |
141+
| `(config: { x: String })` | `foo(config: { x: "hi" })` - Hashリテラル |
142+
143+
**重要なルール**: 変数名の有無で意味が決まります:
144+
- `{ ... }` (変数名なし) → キーワード引数(分割代入)
145+
- `name: { ... }` (変数名あり) → Hashリテラル
141146

142147
:::
143148

144149
### インライン型方式
145150

146-
型を `**{ }` 内に直接定義します。デフォルト値は `= value` 形式で指定します:
151+
型を `{ }` 内に直接定義します。デフォルト値は `= value` 形式で指定します:
147152

148153
```trb title="keyword_inline.trb"
149-
def create_post(**{
154+
def create_post({
150155
title: String,
151156
content: String,
152157
published: Boolean = false,
@@ -186,7 +191,7 @@ interface PostOptions
186191
tags?: Array<String>
187192
end
188193
189-
def create_post(**{ title:, content:, published: false, tags: [] }: PostOptions): Post
194+
def create_post({ title:, content:, published: false, tags: [] }: PostOptions): Post
190195
Post.new(
191196
title: title,
192197
content: content,
@@ -203,7 +208,7 @@ post = create_post(title: "Hello", content: "World")
203208

204209
| 項目 | インライン型 | interface参照 |
205210
|------|------------|---------------|
206-
| 型定義の場所 | `**{ }` 内に直接 | 別途interface |
211+
| 型定義の場所 | `{ }` 内に直接 | 別途interface |
207212
| デフォルト値構文 | `= value` | `: value`(等号なし) |
208213
| Optional表示 | デフォルト値で暗示 | `?` 接尾辞 |
209214
| 再利用性 | 単一メソッド | 複数メソッドで共有 |
@@ -226,14 +231,14 @@ def create_config(env: String, **options: Hash<Symbol, String | Integer | Boolea
226231
end
227232
228233
# キーワード残余パラメータの使用
229-
query1 = build_query(table: "users", id: 123, active: 1)
234+
query1 = build_query("users", id: 123, active: 1)
230235
# "SELECT * FROM users WHERE id = 123 AND active = 1"
231236
232-
query2 = build_query(table: "posts", author_id: 5, published: 1, category: "tech")
237+
query2 = build_query("posts", author_id: 5, published: 1, category: "tech")
233238
# "SELECT * FROM posts WHERE author_id = 5 AND published = 1 AND category = tech"
234239
235240
config = create_config(
236-
env: "production",
241+
"production",
237242
debug: false,
238243
timeout: 30,
239244
host: "example.com"
@@ -247,7 +252,7 @@ config = create_config(
247252
デフォルト値のないキーワード引数は必須です:
248253

249254
```trb title="required_kwargs.trb"
250-
def register_user(**{
255+
def register_user({
251256
email: String,
252257
password: String,
253258
name: String = "Anonymous",
@@ -280,15 +285,15 @@ user2 = register_user(
280285
1. 必須位置パラメータ
281286
2. オプショナル位置パラメータ
282287
3. 残余パラメータ (`*args`)
283-
4. キーワード引数 (`**{ ... }`)
288+
4. キーワード引数 (`{ ... }`)
284289
5. キーワード残余パラメータ (`**kwargs`)
285290

286291
```trb title="all_types.trb"
287292
def complex_function(
288293
required_pos: String, # 1. 必須位置
289294
optional_pos: Integer = 0, # 2. オプショナル位置
290295
*rest_args: Array<String>, # 3. 残余パラメータ
291-
**{
296+
{
292297
required_kw: Boolean, # 4. 必須キーワード
293298
optional_kw: String = "default" # 5. オプショナルキーワード
294299
},
@@ -339,7 +344,7 @@ class HTTPRequestBuilder
339344
end
340345
341346
# キーワード引数(インライン型)
342-
def request(**{
347+
def request({
343348
method: String,
344349
url: String,
345350
body: String? = nil,
@@ -481,7 +486,7 @@ logger.debug(
481486

482487
4. **コレクションには残余パラメータを使用する**: 可変数の類似アイテムを期待する場合、残余パラメータは配列パラメータよりもクリーンです。
483488

484-
5. **残余パラメータに適切な型を付ける**: 文字列のみを期待する場合、`*args: String | Integer`より`*args: String`の方が良いです。
489+
5. **残余パラメータに適切な型を付ける**: 文字列のみを期待する場合、`*args: Array<String | Integer>`より`*args: Array<String>`の方が良いです。
485490

486491
6. **複雑なシグネチャを文書化する**: 多くのパラメータタイプを組み合わせる場合、使用法を説明するコメントを追加します。
487492

@@ -490,7 +495,7 @@ logger.debug(
490495
### デフォルト付きビルダーメソッド(キーワード引数)
491496

492497
```trb title="builder_pattern.trb"
493-
def build_email(**{
498+
def build_email({
494499
to: String,
495500
subject: String,
496501
from: String = "[email protected]",
@@ -508,7 +513,7 @@ email = build_email(to: "[email protected]", subject: "Hello")
508513
### 可変ファクトリ関数(残余 + キーワード引数)
509514

510515
```trb title="factory.trb"
511-
def create_users(*names: Array<String>, **{ role: String = "user" }): Array<User>
516+
def create_users(*names: Array<String>, { role: String = "user" }): Array<User>
512517
names.map { |name| User.new(name: name, role: role) }
513518
end
514519
@@ -538,12 +543,14 @@ config = merge_config(
538543
| `(x: Type)` | 位置引数 | `foo("hi")` |
539544
| `(x: Type = default)` | オプショナル位置引数 | `foo()` または `foo("hi")` |
540545
| `(*args: Array<Type>)` | 残余パラメータ | `foo("a", "b", "c")` |
541-
| `(**{ x: Type })` | キーワード引数 | `foo(x: "hi")` |
546+
| `({ x: Type })` | キーワード引数 | `foo(x: "hi")` |
547+
| `(config: { x: Type })` | Hashリテラル | `foo(config: { x: "hi" })` |
542548
| `(**kwargs: Hash<Symbol, Type>)` | キーワード残余 | `foo(a: 1, b: 2)` |
543549

544550
**重要なポイント:**
545551
- **位置引数** `(x: Type)`: 順序で渡す
546-
- **キーワード引数** `(**{ x: Type })`: 名前で渡す
552+
- **キーワード引数** `({ x: Type })`: 名前で渡す(変数名なし = 分割代入)
553+
- **Hashリテラル** `(config: { x: Type })`: 変数名あり = Hash
547554
- **キーワード残余** `(**kwargs: Hash<Symbol, Type>)`: 任意のキーワード引数をハッシュに収集
548555
- T-Rubyはすべてのパラメータのバリエーションに対して型安全性を保証します
549556

i18n/ja/docusaurus-plugin-content-docs/current/reference/cheatsheet.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,20 @@ def greet(name: String, greeting: String = "Hello"): String
6060
end
6161
6262
# 残余パラメータ
63-
def sum(*numbers: Integer): Integer
63+
def sum(*numbers: Array<Integer>): Integer
6464
numbers.sum
6565
end
6666
67-
# キーワード引数
68-
def create_user(name: String, email: String, age: Integer = 18): Hash
67+
# キーワード引数(変数名なし = 分割代入)
68+
def create_user({ name: String, email: String, age: Integer = 18 }): Hash
6969
{ name: name, email: email, age: age }
7070
end
7171
72+
# Hashリテラル(変数名あり)
73+
def process(config: { host: String, port: Integer }): String
74+
"#{config[:host]}:#{config[:port]}"
75+
end
76+
7277
# 戻り値なし
7378
def log(message: String): void
7479
puts message

i18n/ja/docusaurus-plugin-content-docs/current/reference/stdlib-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
- `File.readlines(path: String): Array<String>`
4949
- `File.open(path: String, mode: String): File`
5050
- `File.open(path: String, mode: String, &block: Proc<File, void>): void`
51-
- `File.delete(*paths: String): Integer`
51+
- `File.delete(*paths: Array<String>): Integer`
5252
- `File.rename(old: String, new: String): Integer`
5353
- `File.size(path: String): Integer`
5454
- `File.directory?(path: String): Boolean`

0 commit comments

Comments
 (0)