]]>ruby瀛︿範絎旇銆婁簩銆?/title>http://www.shnenglu.com/skyscribe/archive/2012/02/19/ruby-study-1.htmlskyscribeskyscribeSun, 19 Feb 2012 11:29:00 GMThttp://www.shnenglu.com/skyscribe/archive/2012/02/19/ruby-study-1.htmlhttp://www.shnenglu.com/skyscribe/comments/165993.htmlhttp://www.shnenglu.com/skyscribe/archive/2012/02/19/ruby-study-1.html#Feedback0http://www.shnenglu.com/skyscribe/comments/commentRss/165993.htmlhttp://www.shnenglu.com/skyscribe/services/trackbacks/165993.html鏉ユ簮錛?br />
Yukihiro Matsumoto: You can reconvert a closure back into a block, so a closure can be used anywhere a block can be used. Often, closures are used to store the status of a block into an instance variable, because once you convert a block into a closure, it is an object that can by referenced by a variable. And of course closures can be used like they are used in other languages, such as passing around the object to customize behavior of methods. If you want to pass some code to customize a method, you can of course just pass a block. But if you want to pass the same code to more than two methods -- this is a very rare case, but if you really want to do that -- you can convert the block into a closure, and pass that same closure object to multiple methods.
7縐嶇粨鏋?/h2>
block鏂瑰紡3縐?/li>
闅愬紡浼犲叆錛屽唴閮ㄧ敤yield璋冪敤
def thrice yield yield yield
end
x=1
thrice {x+=2}
&block鍙傛暟浼犲叆錛屽唴閮ㄧ洿鎺ユ搷浣?amp;block
def six_times(&block)
thrice(&block)
thrice(&block)
end
x =4
six_times { x +=10 }
&block浼犲叆錛屼繚瀛榖lock涓哄彉閲忥紝鐒跺悗璋冪敤block.call
def save_for_later(&b)
@saved = b # Note: no ampersand! This turns a block into a closure of sorts. end
save_for_later { puts "Hello!" }
puts "Deferred execution of a block:"
@saved.call
@saved.call
榪欓噷鐨剆aved淇濆瓨涓簃ain瀵硅薄鐨勪竴涓垚鍛橈紝鍚庤竟瀹炵幇寤惰繜璋冪敤銆?br />
Proc.new/proc
@saved_proc_new = Proc.new { puts "I'm declared with Proc.new." }
@saved_proc = proc { puts "I'm declared with proc." }
@saved_proc_new.call
@saved_proc.call
lambda
@saved_lambda =lambda { puts "I'm declared with lambda." }
@saved_lambda.call
method
def some_method
puts "I'm declared as a method."
end
@method_as_closure = method(:some_method)
]]>Unix鏂囨湰澶勭悊涔嬪埄鍣紞awk/gawkhttp://www.shnenglu.com/skyscribe/archive/2011/01/02/awk.htmlskyscribeskyscribeSun, 02 Jan 2011 12:32:00 GMThttp://www.shnenglu.com/skyscribe/archive/2011/01/02/awk.htmlhttp://www.shnenglu.com/skyscribe/comments/137894.htmlhttp://www.shnenglu.com/skyscribe/archive/2011/01/02/awk.html#Feedback0http://www.shnenglu.com/skyscribe/comments/commentRss/137894.htmlhttp://www.shnenglu.com/skyscribe/services/trackbacks/137894.htmlsince 1977錛夈備綔鑰呬腑鏈寮曚漢娉ㄧ洰鐨勫綋灞為紟榧庡ぇ鍚嶇殑Brian W. Kernighan (鍗矺鐨勭畝縐版潵婧愶級銆傜洰鍓嶆墍鐢ㄧ殑鐗堟湰澶у鏄痝awk鎴栬卬awk.
]]>Popen涓鎬殑OSError錛歵oo many open fileshttp://www.shnenglu.com/skyscribe/archive/2009/10/19/98970.htmlskyscribeskyscribeMon, 19 Oct 2009 11:31:00 GMThttp://www.shnenglu.com/skyscribe/archive/2009/10/19/98970.htmlhttp://www.shnenglu.com/skyscribe/comments/98970.htmlhttp://www.shnenglu.com/skyscribe/archive/2009/10/19/98970.html#Feedback0http://www.shnenglu.com/skyscribe/comments/commentRss/98970.htmlhttp://www.shnenglu.com/skyscribe/services/trackbacks/98970.html榪戞潵鐢≒ython鐨剈nittest妗嗘灦鏉ュ仛涓涓猺egression test 宸ュ叿錛岄獙璇佷竴浜涘鏉傜殑紼嬪簭鍔熻兘錛屾湡鏈涘仛鍒拌嚜鍔ㄥ寲嫻嬭瘯瀹屾垚涓閮ㄥ垎闇瑕佺箒鐞愮殑鐣岄潰鐐瑰嚮鍜岀瓑寰呮墠鑳藉畬鎴愮殑楠岃瘉宸ヤ綔銆?/font>