How to make myself def class act as array in ruby?

class Heap
  attr_accessor :a, :heap_size
  def initialnize(a, heap_size)
    @a = a
    @heap_size = heap_size
  end
end
a = [16, 14, 10, 8, 7, 9, 3, 2, 4, 1]
a = Heap.new(a, a.length-1)

what should I do? Then I can aceess 16 use a[i],etc.


Source: ruby

1 Comment

  1. Digin Dominic

    You can simply use inheritance:

    class Heap 16

    Reply

Leave a Reply