开发者

Why use () as the hash?

I saw some hash like the following in some .rb configuration file

cache( :path => "#{currentDir}/cache" )

wh开发者_如何学编程y not using {}?


cache is a method, syntax like

      method( a => b , c => d )

is a shorthand (syntactic sugar) for

       method({ a => b , c => d})


In ruby, if the only argument of a method is a hash, the braces are assumed.

edit To clear it up: cache() is a method, which takes a hash as its argument, probably like this:

def cache(*args)
   # ...
end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜