我刚看了下面的代码:
class Dir
def self.create_uniq &b ### Here, & should mean b is a block
u = 0
loop do
begin
fn = b[u] ### But, what does b[u] mean? And b is not called.
FileUtils.mkdir fn
return fn
rescue Errno::EEXIST
u += 1
end
end
io
end
end
Run Code Online (Sandbox Code Playgroud)
我把我的困惑作为评论在代码中.
Mar*_*pka 12
最后定义方法&b
允许您使用传递给方法的块作为Proc
对象.
现在,如果你有Proc
实例,[]
语法是简写call
:
p = Proc.new { |u| puts u }
p['some string']
# some string
# => nil
Run Code Online (Sandbox Code Playgroud)
记录在这里 - > Proc#[]
归档时间: |
|
查看次数: |
375 次 |
最近记录: |