例如,我有一個對象x,它可能是None或浮點數的字符串表示形式。我要做到以下幾點: do_stuff_with(float(x) if x else None)
除了不必鍵入x兩次,與Ruby的andand庫: require 'andand'
do_stuff_with(x.andand.to_f)
我只是試圖運行一些代碼,看起來像這樣 def get_proj4(srid, type=nil)
type.downcase! if type
case type
when nil || "epsg"
open("http://spatialreference.org/ref/epsg/#{srid}/proj4/").read
when "esr
我寧願這樣做: say $shop->ShopperDueDate->andand->day_name();
與此: say $shop->ShopperDueDate->day_name() if $shop->ShopperDueDate;
任何想法? (這個想法是由紅寶石andand擴展的啓發) (實際上它是由Groovy語言啓發,但大多數人不知道;-) 更新:我認爲maybe()和