From 212c8be573cd54379232eec925cb82b1c337b492 Mon Sep 17 00:00:00 2001 From: h-east Date: Sun, 14 Apr 2024 05:22:37 +0900 Subject: [PATCH 1/2] Update vim9class.{txt,jax} --- doc/vim9class.jax | 36 +++++++++++++++++++++++++++--------- en/vim9class.txt | 33 +++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/doc/vim9class.jax b/doc/vim9class.jax index ff19c1c3c..22c97fda8 100644 --- a/doc/vim9class.jax +++ b/doc/vim9class.jax @@ -1,4 +1,4 @@ -*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Mar 28 +*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Apr 13 VIMリファレンスマニュアル by Bram Moolenaar @@ -323,10 +323,28 @@ new() メソッドを定義するときは、戻り値の型を指定しない enddef endclass -クラス内ではクラスメソッドを名前で直接呼び出すことができるが、クラスの外ではク -ラス名はプリフィックス付きである必要がある: `OtherThing.ClearTotalSize()`。親 -クラスのクラスメソッドを子クラスで使用するには、クラス名をプリフィックスとして -付ける必要がある。 +クラス内では、クラスメソッドを名前で直接呼び出すことができるが、クラスの外で +は、クラス名はプリフィックス付きである必要がある: +`OtherThing.ClearTotalSize()`。また、クラス変数初期化子、ラムダ式、入れ子になっ +た関数の特殊なコンテキストでは、パブリッククラスメソッドに名前プリフィックスを +使用しなければならない: +> + class OtherThing + static var name: string = OtherThing.GiveName() + + static def GiveName(): string + def DoGiveName(): string + return OtherThing.NameAny() + enddef + + return DoGiveName() + enddef + + static def NameAny(): string + return "any" + enddef + endclass +< オブジェクトメソッドと同様に、メソッド名の最初の文字としてアンダースコアを使用 することで、アクセスを protected にすることができる: > @@ -571,8 +589,8 @@ Shape, Square および Triangle を使用した上記の例は、オブジェ クラスは `:class` と `:endclass` の間で定義される。クラス全体は 1 つのスクリプ トファイルで定義される。後からクラスに追加することはできない。 -クラスは |Vim9| script ファイル内でのみ定義できる。 *E1316* -関数内でクラスを定義することはできない。 +クラスは |Vim9| script ファイル内でのみ定義できる。 *E1316* +関数内でクラスを定義することはできない。 *E1429* スクリプトファイル内に複数のクラスを定義することは可能である。しかし、通常はメ インクラスを 1 つだけエクスポートする方が良い。型、列挙型、ヘルパークラスを定 @@ -959,8 +977,8 @@ Note メソッド名は "new" で始まる必要があることに注意。"new( echo Planet.Earth.has_rings < *E1421* *E1423* *E1424* *E1425* -列挙型とその値は不変である。宣言後に変更したり、数値型または文字列型として使用 -したりすることはできない。 +列挙型とその値は不変である。数値型または文字列型として使用することはできない。 +列挙値は変更可能なインスタンス変数を宣言できる。 *enum-name* 各列挙値オブジェクトには、列挙値の名前を含む "name" インスタンス変数がある。こ diff --git a/en/vim9class.txt b/en/vim9class.txt index 8820d77b5..ef96aa907 100644 --- a/en/vim9class.txt +++ b/en/vim9class.txt @@ -1,4 +1,4 @@ -*vim9class.txt* For Vim version 9.1. Last change: 2024 Mar 28 +*vim9class.txt* For Vim version 9.1. Last change: 2024 Apr 13 VIM REFERENCE MANUAL by Bram Moolenaar @@ -328,10 +328,27 @@ variables but they have no access to the object variables, they cannot use the enddef endclass -Inside the class the class method can be called by name directly, outside the -class the class name must be prefixed: `OtherThing.ClearTotalSize()`. To use -a class method from a parent class in a child class, the class name must be -prefixed. +Inside the class, the class method can be called by name directly, outside the +class, the class name must be prefixed: `OtherThing.ClearTotalSize()`. Also, +the name prefix must be used for public class methods in the special contexts +of class variable initializers and of lambda expressions and nested functions: +> + class OtherThing + static var name: string = OtherThing.GiveName() + + static def GiveName(): string + def DoGiveName(): string + return OtherThing.NameAny() + enddef + + return DoGiveName() + enddef + + static def NameAny(): string + return "any" + enddef + endclass +< Just like object methods the access can be made protected by using an underscore as the first character in the method name: > @@ -576,7 +593,7 @@ A class is defined between `:class` and `:endclass`. The whole class is defined in one script file. It is not possible to add to a class later. A class can only be defined in a |Vim9| script file. *E1316* -A class cannot be defined inside a function. +A class cannot be defined inside a function. *E1429* It is possible to define more than one class in a script file. Although it usually is better to export only one main class. It can be useful to define @@ -972,8 +989,8 @@ The following example shows an enum with object variables and methods: > echo Planet.Earth.has_rings < *E1421* *E1423* *E1424* *E1425* -Enums and their values are immutable. They cannot be modified after -declaration and cannot be utilized as numerical or string types. +Enums and their values are immutable. They cannot be utilized as numerical or +string types. Enum values can declare mutable instance variables. *enum-name* Each enum value object has a "name" instance variable which contains the name From defc29eb751efb3c6e983a30097896f8ed46f82e Mon Sep 17 00:00:00 2001 From: h-east Date: Mon, 29 Apr 2024 10:29:12 +0900 Subject: [PATCH 2/2] Fix by review --- doc/vim9class.jax | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/vim9class.jax b/doc/vim9class.jax index 22c97fda8..0535f5d9b 100644 --- a/doc/vim9class.jax +++ b/doc/vim9class.jax @@ -324,10 +324,10 @@ new() メソッドを定義するときは、戻り値の型を指定しない endclass クラス内では、クラスメソッドを名前で直接呼び出すことができるが、クラスの外で -は、クラス名はプリフィックス付きである必要がある: +は、クラス名がプリフィックスされている必要がある: `OtherThing.ClearTotalSize()`。また、クラス変数初期化子、ラムダ式、入れ子になっ -た関数の特殊なコンテキストでは、パブリッククラスメソッドに名前プリフィックスを -使用しなければならない: +た関数といった特殊なコンテキストでは、パブリッククラスメソッドに名前プリフィッ +クスを使用しなければならない: > class OtherThing static var name: string = OtherThing.GiveName()