Objectのattributesの中身を変更する別の方法

配列で一気に attributes を変更したい場合などに

book = Book.new
book_atts = book.instance_variable_get(:@attributes)
book_atts.each do |ba|
  book_atts[ba[0]] = array[ba[0]]
end
book.instance_variable_set(:@attributes, book_atts)
 
comments powered by Disqus