Mongoid如何知道字符串值和符号值之间的区别?

law*_*nce 5 ruby mongodb mongoid mongoid3

考虑这个例子:

> x = User.first # or any persisted Mongoid::Document
=> #<User _id: 52014532a6356d1ac9000001, ...>
> x.set :foo, :bar
=> :bar
> x.set :foo2, 'bar'
=> "bar"
Run Code Online (Sandbox Code Playgroud)

请注意,"foo"和"foo2"未在Ruby中声明.

那么,在MongoDB shell中:

> db.users.findOne({_id: ObjectId('52014532a6356d1ac9000001')})    
{
  "_id" : ObjectId("52014532a6356d1ac9000001"),
  "foo" : "bar",
  "foo2" : "bar",
  ...
}
Run Code Online (Sandbox Code Playgroud)

但现在,回到Ruby:

> x = User.find x.id; nil # to clear out any possibility of metadata on the instance
=> nil
> [x.read_attribute(:foo), x.read_attribute(:foo2)]
=> [:bar, "bar"]
Run Code Online (Sandbox Code Playgroud)

怎么知道的?