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
精彩评论