Smalltalk中.
的用法是什么?根据我的理解,它是不同语句的分隔符,但是如果语句末尾可以省略。正确吗?
.
是一个语句分隔符,类似于;
中的C
(通常在行尾使用)。原因是英语中的普通句子以.
结尾。
可以省略的地方是:
变量定义
评论
一个语句块(块中的最后一条语句)
方法末尾
Smalltalk / X中的示例方法:
selectorAsRegistryName: aSelector
"Splits selector into string words with spaces.
For example: itemName becomes 'Item Name'"
| registryName selectorCollection |
registryName := String new.
selectorCollection := aSelector asCollectionOfSubCollectionsSeparatedByAnyForWhich:[:ch | ch isUppercase ] withSeparatorsIncluded:true.
selectorCollection at: 1 put: selectorCollection copy first asUppercaseFirst. "/ first string must be uppercase too
selectorCollection do: [ :eachString |
registryName := registryName isEmpty ifTrue: [ eachString ]
ifFalse: [ registryName, Character space, eachString ]
].
^ registryName