- 博客(3)
- 收藏
- 关注
原创 ruby 中的as_json 和 to_json的区别
as_json返回模型对象的散列表示,而to_json返回一个json对象。a= {'a': 1, 'b': 2}a.to_json #=>"{\"a\":1,\"b\":2}"a.as_json #=> {"a"=>1, "b"=>2}
2018-02-06 21:54:39 2654
转载 pluck
Person.pluck(:name)# SELECT people.name FROM people# => ['David', 'Jeremy', 'Jose']Person.pluck(:id, :name)# SELECT people.id, people.name FROM people# => [[1, 'David'], [2, 'Jeremy'], [3, 'Jose
2017-11-02 14:16:43 346
转载 ruby eql?
ary1 = [ ]ary2 =[ ]p ary1.object_id #67653636pary2.object_id #67650432equal? 方法判断两个对象是否是同一个对象(ID是否相同)str1 = "foo"str2 = str1str3 = "f"+ "o"+ "o"p str1.equal?(str2) #=> t
2017-10-28 09:49:27 249
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人