gpt4 book ai didi

pharo - 如何在 Pharo 中添加新方法?

转载 作者:行者123 更新时间:2023-12-05 02:14:41 26 4
gpt4 key购买 nike

在 Nautilus 系统浏览器 (Pharo 6) 中,有一个右键单击命令可以Add package... 以及 Add class... 甚至 Add protocol...,但我无法在任何地方找到Add method... 的方法。

那个命令在哪里?

最佳答案

在 Pharo 中,添加方法不像其他元素那样明确。添加新方法:

  1. 选择方法的协议(protocol),您应该会在编辑器 Pane 中看到一个模板:

    messageSelectorAndArgumentNames
    "comment stating purpose of message"

    | temporary variable names |
    statements
  2. 编辑此模板以创建新方法,

  3. 使用 Ctrl-S 保存(右键单击接受)。

事实上,任何时候您更改方法的定义(例如,messageSelectorAndArgumentNames)并将其保存在编辑器中(右键单击接受Ctrl-S),它将创建一个新方法

enter image description here

有关详细信息,请参阅 Developing a simple counter 的第 1.3 节文档(重点是我的):

Create a method

Now let us create the accessor methods for the instance variable count. Start by selecting the class Counter in a browser, and make sure the you are editing the instance side of the class (i.e., we define methods that will be sent to instances) by deselecting the Class side radio button.

Create a new protocol by bringing the menu of methods protocol list. Select the newly created protocol. Then in the bottom pane, the edit field displays a method template laying out the default structure of a method. As a general hint, double click at the end of or beginning of the text and start typing your method. Replace the template with the following method definition:

count
"return the current value of the value instance variable"
^ count

This defines a method called count, taking no arguments, having a method comment and returning the instance variable count. Then choose accept in the menu to compile the method.

关于pharo - 如何在 Pharo 中添加新方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53374761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com