0.0
No commit activity in last 3 years
No release in over 3 years
Sort a collection of objects using one or more of the attributes of your object.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 1.2.9
 Project Readme

attributes_sort¶ ↑

This gem allows you to take a collection of any type of object and sort them using the attributes of the object.

Example:

require 'rubygems'
require 'attributes_sort'

class Person
  include AttributesSort

  attr_accessor :firstname,:lastname,:age

  def initialize(firstname="", lastname="" ,age=0)
    @firstname = firstname
    @lastname = lastname
    @age = age
  end
end

people = [
  Person.new("joe","blow",12),
  Person.new("joe","blow",89),
  Person.new("mary","watson",32),
  Person.new("annie","watson",9),
  Person.new("bob","builder",12)
]
p people.attr_sort(:sort_by=>[:lastname])
p people.attr_sort(:sort_by=>[:age])
p people.attr_sort(:sort_by=>[:lastname,:firstname,:age])

Copyright © 2009 Karmen Blake. See LICENSE for details.