Apr 06
While there are plenty of places on the web that talk about Ruby Arrays and Ruby Classes, I never have found one that just explained how to use a Class as an Array. So I thought I would post one for those who might want something simple to reference
First, the sample code:
class Test
@dd = Array.new
def initialize
@dd = loadArray()
end
def [](a)
@dd[a]
end
def []=(a, b)
@dd[a] = b
end
def list
@dd.each do |i|
puts i
end
end
def sort
aa = Array.new
aa = @dd.sort
@dd = aa
end
private
def loadArray
rr = Array.new
rr << "one"
rr << "two"
rr << "three"
rr << "four"
return rr
end
end






