开发者

Can't understand yield

开发者 https://www.devze.com 2023-02-18 01:40 出处:网络
In some project i met this code: erb = yield.src I can\'t understan开发者_C百科d what the src method is doing and how it\'s possible to chain to yield method.

In some project i met this code:

erb = yield.src

I can't understan开发者_C百科d what the src method is doing and how it's possible to chain to yield method.

Thanks


As far as I understand yield would return an object which has the instance method src defined on it

something like this

def foo
  p yield.class
end

foo do 
 1
end  

This will print Fixnum

0

精彩评论

暂无评论...
验证码 换一张
取 消