array

Clean 2D Arrays in Ruby

    I've recently found myself needing a simple and clean way to handle
2D arrays in ruby, so I created a Matrix class for that purpose. It's certainly not abiding by a lot of ruby style guidelines, but it's the cleanest way I can think of to handle 2D arrays.

Moving Elements in a Ruby Array by Name

    This is an extension to my previous tip about moving elements in ruby arrays around. In fact, this is yet another mixin that only has one line of real code, and even though it's quite obvious I thought I'd post it here.

Moving Elements in Ruby Arrays

    Today in my coding of droppit I needed to keep an ordered list of mimetypes sorted by priority, as such I needed some way to 'move' them around the array. Since there is no included way in the ruby Array class to do this, with the help of my friends in #ruby on freenode I have this snippet of code for you.

# Mixin for Array that allows you
# to move elements arround easily
module Reorderable
  def move(from, to)
    insert(to, delete_at(from))
  end
end