ruby 中 關于 yield 的用法 誰能給講一下? def fibUpTo(max) i1,i2=1,1 #parallel assignment while i1<=max yield i1 i1, i2 =i2,i1+i2 end end fibUpTo(1000){|f| print f," "}
如何去理解 yield ? 有了解的指點一下嗎?。。?/h1>
1 回答

拉丁的傳說
TA貢獻1789條經驗 獲得超8個贊
其實就是一個占位符, 把塊的內容部份粘進去,
例如,
def test
yield
end
test do
puts 'this is a test'
end
上面test方法中的yield就是 puts 'this is a test'
- 1 回答
- 0 關注
- 194 瀏覽
添加回答
舉報
0/150
提交
取消