在rails控制台上输出它的意思#<在下面的例子中?:

时间:2013-08-02 16:53:36

标签: ruby-on-rails console

在rails控制台上输出在以下示例的哈希开头是什么意思#<?:

irb(main):003:0> a=Movie.all
Movie Load (0.5ms)  SELECT "movies".* FROM "movies" 
=> [#<Movie id: 1, title: "Aladdin", rating: "G", description: nil, release_date: "1992-11-25 00:00:00", created_at: "2013-07-27 21:29:01", updated_at: "2013-07-27 21:29:01">, #  <Movie id: 2, title: "The Terminator", rating: "R", description: nil, release_date: "1984-10- 26 00:00:00", created_at: "2013-07-27 21:29:01", updated_at: "2013-07-27 21:29:01">, #<Movie id: 3, title: "When Harry Met Sally", rating: "R", description: nil, release_date: "1989-07-21 00:00:00", created_at: "2013-07-27 21:29:01", updated_at: "2013-07-27 21:29:01">,...  more output

2 个答案:

答案 0 :(得分:1)

这就是如何在ruby中打印一个对象,例如,类的实例Movie将打印出类似这样的内容:

<#Movie:0x003247fa... >
    |          |
   class      memory position I think

你所拥有的是前一篇文章:

[ one_object, other_object ... ]

为了获得更好的显示效果,您可以使用hirb

答案 1 :(得分:0)

#<表示这是Movie类的一个实例。