sheefo
July 30th, 2006, 09:48 AM
I need to arrange an array or hash in order of there objects attributes. Like this:
$LAYERS = Array.new
class Bitmap
attr_accessor :layer
def initialize
$LAYERS << self
end
end
bitmap = Bitmap.new
bitmap.layer = 10
bitmap2 = Bitmap.new
bitmap2.layer = 999
def update
# CODE for Arranging an Array
end
'bitmap2' should be before 'bitmap' in the array and if you add a new one the code for re-arranging the array initializes again.
$LAYERS = Array.new
class Bitmap
attr_accessor :layer
def initialize
$LAYERS << self
end
end
bitmap = Bitmap.new
bitmap.layer = 10
bitmap2 = Bitmap.new
bitmap2.layer = 999
def update
# CODE for Arranging an Array
end
'bitmap2' should be before 'bitmap' in the array and if you add a new one the code for re-arranging the array initializes again.