• 2022-06-15
    给出如下代码:
    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")
    下列哪段代码是合法的?
    A: "#{book.title} was written by #{book.author}."
    B: book.comments
    C: book.comments.each { |comment| puts comment }
    D: book.title = "Cooking Club"