class Book
include Virtus
attribute :title, String
end
class BookCollection < Array
def <<(book)
if book.kind_of?(Hash)
super(Book.new(book))
else
super
end
end
end
class Library
include Virtus
attribute :books, BookCollection[Book]
end
library = Library.new
library.books << { :title => 'Another Introduction to Virtus' }
When I run this example library.books.class is an Array and not a BookCollection. So I added a default value to the attribute :books:
The note on member coercions includes the following example using a subclass of an Array:
When I run this example
library.books.class
is an Array and not a BookCollection. So I added a default value to theattribute :books
:Should this be added to the docs?