From: Sebastian Sastre <sebastian@flowingconcept.com>
To: Pharo Development List <pharo-dev@lists.pharo.org>
Sent: Sunday, January 4, 2015 5:27 PM
Subject: [Pharo-dev] Object>>ifNilOrEmpty: aBlock
Hi guys,
I���ve started to use this little one:
Object>>ifNilOrEmpty: aBlock
self ifNil: [ ^ aBlock value ].
(self isCollection and: [
self isEmpty ]) ifTrue: [ ^ aBlock value ].
^ self.
It allows you to do the widely known JavaScript one-liner:
var stuff = this.thing || ���some default value for when this.thing is undefined, null or an empty string���.
but in smalltalk in this way:
stuff := self thing ifNilOrEmpty: [ ���some default value for when self thing is nil or an empty string��� ]
simple thing feels practical and nice :)