docs.scala-lang icon indicating copy to clipboard operation
docs.scala-lang copied to clipboard

two or three paragraphs seem missed in _overviews/scala3-book/taste-methods.md

Open benluo opened this issue 2 years ago • 3 comments

After Line 131 in _overviews/scala3-book/taste-methods.md, there should be at least two paragraphs more.

benluo avatar Jan 29 '23 00:01 benluo

Please could you describe more precisely what you mean? It doesn't appear to me that there is missing/deleted text. These two paragraphs are talking about the extension methods example snippet that immediately follows.

Do you mean that there is not enough text, and there should be more text dedicated to explaining other details about extension methods?

bishabosha avatar Jan 30 '23 09:01 bishabosha

In Chinese version, file "_zh-cn/overviews/scala3-book/taste-methods.md" from line 154

如果没有IDE的帮助,那段代码可能很难阅读,但这个代码要明显得多:

{% tabs method_10 %} {% tab 'Scala 2 and 3' for=method_10 %}

engage(
  speedIsSet = true,
  directionIsSet = true,
  picardSaidMakeItSo = true,
  turnedOffParkingBrake = false
)

{% endtab %} {% endtabs %}

扩展方法

扩展方法 允许您向封闭类添加新方法。 例如,如果要将两个名为 helloaloha 的方法添加到 String 类中,请将它们声明为扩展方法:

{% tabs extension0 %} {% tab 'Scala 3 Only' %}

extension (s: String)
  def hello: String = s"Hello, ${s.capitalize}!"
  def aloha: String = s"Aloha, ${s.capitalize}!"

"world".hello    // "Hello, World!"
"friend".aloha   // "Aloha, Friend!"

{% endtab %} {% endtabs %}

But all these lines missed in English version.

benluo avatar Jan 30 '23 11:01 benluo

ah this makes more sense, thanks!

bishabosha avatar Jan 30 '23 14:01 bishabosha

An example of using extension methods has been added in the meantime.

gkepka avatar Nov 18 '24 12:11 gkepka