data: 和 :data in ruby 之间有什么区别

what is the difference between data: and :data in ruby

我在 rails 上与 ruby 合作,在开始 rails 之前,我学习了一些 ruby 并且我知道 about:symbols 因为这些都是独一无二的出我们的应用程序

但是在学习 rails 时,我在使用 rails 模型时遇到了连线符号 symbol:,因为我将 rails 模型创建为

def up
    create_table :users do |t|
        t.string "email", :limit =>50, :null =>false
        t.column "password", :string, :limit =>30, :null => false
        #data types,binary, boolean, data, decima, float, integer,  text, time
        #these are the differentdata types
        #we can also have options
        #:default
        #:precision for decimal
        t.timestamps null: false
    end
  end

我对上面代码中定义的 :nullnull: 感到很困惑,我知道 :null 是符号而 null: 是什么?

都是在Ruby.

中的Hash中定义键值对的语法
# Older Hash syntax; before Ruby 1.9 e.g. { :key => value }
    :limit => 50
    :null => false 

并且:

# Latest Hash syntax; Ruby 1.9 and higher versions e.g. { key: value }
    null: false 
    limit: 50

在这两种情况下,null 都是符号。

请参阅 Ruby 1.9 and the new hash syntax

上的这篇短文

symbol: true:symbol => true 完全相同。 symbol: 只是 ruby 1.9 及更高版本中的新语法。

在ruby1.8.7及以下版本中,仅支持:symbol => true。在 ruby 1.9+ 中,这两个都受支持。