ruby 中 關(guān)于 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," "}
1 回答

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