Search code examples
rubychef-infrachef-recipechefdk

What is the difference between quotation marks and the colon in chef attributes?


I am currently creating a wrapper cookbook, while trying to restrict myself to the correct formatting by using Rubocop and Foodcritic. However, I constantly get the following errors:

Use strings in preference to symbols to access node attributes

and

Access node attributes in a consistent manner

this made me wonder, Is there a difference between colons and quotation marks?


Solution

  • Yes...colons are used for defining symbols while strings are defined by quotes... so:

    :variable1 is a symbol named variable1

    :'variable is 1' is a symbol

    'variable1' - is a string

    "variable#{1}" - is a string that could have variables defined in it. Double quotes interpret the string while single quotes use the string as is.

    and

    'variable1'.to_sym is same as :variable1