什么将输出给定的代码

时间:2012-10-08 18:48:46

标签: ruby-on-rails ruby-on-rails-3

给出以下代码:

  class Book
    attr_accessor :author
    attr_reader :title
    attr_writer :comments
    def initialize(author, title)
      @author = author
      @title = title
      @comments = []
    end
  end

  book = Book.new("Chuck Palahniuk", "Fight Club")

以下哪些代码片段有效?

1.“#{book.title}由#{book.author}撰写。”

2.book.comments<< “#{book.title}是一本好书”

book.comments.each {|评论|放评论}

book.title =“烹饪俱乐部”

1 个答案:

答案 0 :(得分:4)

答案是#1 ......我如何获得巧克力?

#2 - There is no attr_accessor or attr_writer for comments
#3 - There is no attr_accessor or attr_reader for comments
#4 - There is no attr_accessor or attr_writer for title