在Ruby中,哈希中的标识符后冒号的含义是什么? [英] In Ruby what is the meaning of colon after identifier in a Hash?

查看:126
本文介绍了在Ruby中,哈希中的标识符后冒号的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 工厂:post do 
关联:作者,工厂:: user,last_name:Writely
结束

为什么 factory last_name 在它们的最后有一个冒号?

解决方案

在此上下文中的冒号表示文字哈希。



工厂 Hash 键,:user 是值。



替代语法是:factory => :用户。他们的意思是一样的。


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

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

why do factory and last_name have a colon at their end?

解决方案

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.

这篇关于在Ruby中,哈希中的标识符后冒号的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆