在Ruby中,我想選擇一個塊的默認對象。在Ruby中,有什麼方法可以完成Actionscript中的`with`操作?
在Actionscript中的一個例子是:
with (board) {
length = 66;
width = 19;
fin_system = 'lockbox';
}
即相當於:
board.length = 66;
board.width = 19;
board.fin_system = 'lockbox';
這裏是ActionScript則聲明的文檔: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/statements.html#with
我怎樣才能做到這一點在Ruby中?
爲什麼要使用?除了_eval_,_with_是ECMAScript(a.k.a. javascript和actionscript)中最糟糕的部分 – 2011-04-13 19:05:00
@invisible bob,你爲什麼認爲'with'是壞的?只爲興趣 – fl00r 2011-04-13 19:14:24
@invisible bob,最簡單/最快的答案是遵循DRY原則。重複鍵入'board.'不是乾的。 – 2011-04-13 21:50:56