Moving Elements in a Ruby Array by Name
By snuxoll - November 19th, 2008
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.
# Adds the ability to reoder elements by name, # it requires the object extended # to support the Reorderable module and have # a #index_of method module NameReorderable # Moves an element around an orderable # list by its name def move_by_name(name, to) move(index(name), to) end end















Comments
Post new comment