class Squirrel
attr_reader :nuts
def initialize
@nuts = []
end
def add(nut)
nuts << nut
end
end
sq = Squirrel.new sq.add :one sq.add :two puts sq.inspect
=> #<Squirrel:0x00000001cefe40 @nuts=[:one, :two]>
sq.nuts.delete_at 0
puts sq.inspect
=> #<Squirrel:0x00000001cefe40 @nuts=[:two]>
class Squirrel
def initialize
@nuts = []
end
def add(nut)
@nuts << nut
end
def nuts
@nuts.dup
end
end
module Forest
class Hamster
attr_reader :seeds
def initialize
@seeds = ::Hamster.vector
end
def add(seed)
@seeds = @seeds << seed
end
end
end
h = Forest::Hamster.new h.add :one h.add :two puts h.inspect h.seeds.delete_at 0
=> #<Forest::Hamster:0x000000014dc230 @seeds=[:one, :two]>
=> NoMethodError: undefined method `delete_at' for [:one, :two]:Hamster::Vector