Reputation: 727
Look at the following line of chef code:
node.default['apache']['dir'] = '/etc/apache2'
In the official chef docs, it says 'node' is an object, and 'default' is a method of it, so how can square brackets(I thought this is hash syntax) follow a method?
I come from Python background and I'm new to Ruby, maybe this is general syntax, or maybe this is Chef-specific syntax, I'm just confused about this syntax.
Upvotes: 1
Views: 231
Reputation: 54181
node.default()
(which is really an alias for node.attributes().default()
) returns an instance of a Chef::Node::VividMash
which works kind of like a normal Hash
object but implements the deep-set behavior you see there (where you can set a deeply nested key without creating the intervening levels).
tl;dr don't worry about, we do a lot of object trickery to make the DSL look as nice as possible.
Upvotes: 2