2012-10-08 32 views
2

會是怎樣的輸出考慮下面的代碼:的指定代碼

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 = 「烹飪俱樂部」

+3

哪些是獎品? – moonwave99

+0

它是作業時間? – iouri

+1

PRIZE是一顆巧克力 – user1729711

回答

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