• 2022-06-15 问题

    给出如下代码:<br/>class Book<br/>attr_accessor :author<br/>attr_reader :title<br/>attr_writer :comments<br/>def initialize(author, title)<br/>@author = author<br/>@title = title<br/>@comments = &#91;&#93;<br/>end<br/>end<br/>book = Book.new("Chuck Palahniuk", "Fight Club")<br/>下列哪段代码是合法的? A: "#{book.title} was written by #{book.author}." B: book.comments C: book.comments.each { |comment| puts comment } D: book.title = "Cooking Club"

    给出如下代码:<br/>class Book<br/>attr_accessor :author<br/>attr_reader :title<br/>attr_writer :comments<br/>def initialize(author, title)<br/>@author = author<br/>@title = title<br/>@comments = &#91;&#93;<br/>end<br/>end<br/>book = Book.new("Chuck Palahniuk", "Fight Club")<br/>下列哪段代码是合法的? A: "#{book.title} was written by #{book.author}." B: book.comments C: book.comments.each { |comment| puts comment } D: book.title = "Cooking Club"

  • 1