Skip to content

fix example on string-interpolation page #725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions es/overviews/core/string-interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ En este ejemplo, estamos intentando crear una cadena JSON mediante el uso de la

Cuando el compilador encuentra la cadena `json"{ name: $name, id: $id }"` reescribe la siguiente expresión:

new StringContext("{ name:", ",id: ", "}").json(name, id)
new StringContext("{ name: ", ", id: ", " }").json(name, id)

La clase implícita es utilizada para reescribir el fragmento anterior de la siguiente forma:

new JsonHelper(new StringContext("{ name:", ",id: ", "}")).json(name, id)
new JsonHelper(new StringContext("{ name: ", ", id: ", " }")).json(name, id)

De este modo, el método `json` tiene acceso a las diferentes partes de las cadenas así como cada una de las expresiones. Una implementación simple, y con errores, de este método podría ser:

Expand Down
4 changes: 2 additions & 2 deletions ja/overviews/core/string-interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ Scala では、全ての加工文字列リテラルは簡単なコード変換

コンパイラが `json"{ name: $name, id: $id }"` を見つけると、以下の式に書き換える:

new StringContext("{ name:", ",id: ", "}").json(name, id)
new StringContext("{ name: ", ", id: ", " }").json(name, id)

さらに、implicit クラスは以下のように書き換える:

new JsonHelper(new StringContext("{ name:", ",id: ", "}")).json(name, id)
new JsonHelper(new StringContext("{ name: ", ", id: ", " }")).json(name, id)

そのため、`json` メソッドは生の String 部分と渡される式の値をみることができる。シンプルな (だけどバギーな) 実装を以下に示す:

Expand Down
4 changes: 2 additions & 2 deletions overviews/core/_posts/2012-09-21-string-interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ In this example, we're attempting to create a JSON literal syntax using string i

When the compiler encounters the literal `json"{ name: $name, id: $id }"` it rewrites it to the following expression:

new StringContext("{ name:", ",id: ", "}").json(name, id)
new StringContext("{ name: ", ", id: ", " }").json(name, id)

The implicit class is then used to rewrite it to the following:

new JsonHelper(new StringContext("{ name:", ",id: ", "}")).json(name, id)
new JsonHelper(new StringContext("{ name: ", ", id: ", " }")).json(name, id)

So, the `json` method has access to the raw pieces of strings and each expression as a value. A simple (buggy) implementation of this method could be:

Expand Down