Arrayclass is a class factory for generating Array based objects whose attributes can be accessed like those of a normal ruby object (or like an array). They are highly memory efficient (almost equivalent to an Array) and fast to work with.
Arrayclass based objects are:
require 'arrayclass'
Person = Arrayclass.new(%w(name eye_color watch_brand))
# instantiate with an array
joe = Person.new(%w(Joe brown Casio))
# instantiate an empty object (an array of the expected size is created)
sally = Person.new
sally.name = 'Sally'
sally[0] == 'Sally' # true
joe.name # 'Joe'
joe.watch_brand = 'Timex'
joe[1] # 'brown'
joe[1..2] = ['blue', 'Fossil']
joe.each {|attribute| # do something with attribute }
class BigPerson < Person
def some_new_function
end
# push on another attribute
self.add_member('shoe_type')
# (haven't written a remove_member function yet...)
end
BigPerson.new
gem install arrayclass