smalltalk(初学者)(Pharo)中的关键字消息 [英] Keyword messages in smalltalk (Beginner)(Pharo)

查看:89
本文介绍了smalltalk(初学者)(Pharo)中的关键字消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建关键字消息样式方法,但是我不知道如何从该方法内部访问Receiver.我敢肯定这很简单,但是我找不到任何答案.我试图实现的是多余的,但我仍然想知道它是如何工作的.

I am trying to create a keyword message style method, but I can't figure out how to access the Receiver from inside the method. I am sure this is simple, however I can't find the answer anywhere. What I am trying to implement is redundant, but I would still like to know how it works.

subst: i1 by: i2
      ^ self copyReplaceAll: i1 with: i2.

它将在工作空间中按以下方式调用:

It would be called in the workspace as follows:

string1 := 'Lemon'.
string2 := 'm'.
string3 := 'ss'.
string1 subst: string2 by: string3.

错误消息:"MessageNotUnderstood:ByteString >> subst:by:"

Error msg: "MessageNotUnderstood: ByteString>>subst:by:"

该方法应该做的就是用"ss"替换"Lemon"中"m"的每个出现,以创建"Lesson"(copyReplaceAll已经做到了).我不知道如何将string1放入该方法.任何帮助将不胜感激,

All the method should do is replace every occurance of "m" in "Lemon" with "ss" to create "Lesson" (which copyReplaceAll already does). I can't figure out how to get string1 into the method. Any help would be greatly appreciated,

提前谢谢!

推荐答案

self是当前对象(即接收者).

self is the current object (i.e. the receiver).

请阅读(或至少略读)教程以获取基础知识.

"MessageNotUnderstood: ByteString>>subst:by:"

此错误意味着您尚未在ByteString上定义消息.您可能没有在任何地方实际定义它,或者在错误的类上定义了它.

This error means that you have not defined the message on ByteString. Either you have failed to actually define it anywhere, or you have defined it on the wrong class.

这篇关于smalltalk(初学者)(Pharo)中的关键字消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆