In Ruby what is the meaning of colon after identifier in a Hash?

前端 未结 3 1851
暗喜
暗喜 2021-02-05 08:00

I\'m learning about Factory Girl and I saw this code:

factory :post do
  association :author, factory: :user, last_name: \"Writely\"
end

why do

3条回答
  •  鱼传尺愫
    2021-02-05 08:38

    The colon in this context denotes a literal Hash.

    factory is the Hash key, :user is the value.

    The alternative syntax is :factory => :user. They mean the same thing.

提交回复
热议问题