Skip to content

Instantly share code, notes, and snippets.

@kblake
Created March 29, 2010 05:17
Show Gist options
  • Save kblake/347454 to your computer and use it in GitHub Desktop.
Save kblake/347454 to your computer and use it in GitHub Desktop.
class Book
include AttributesSort
attr_accessor :author, :date
def initialize(author, date)
@author = author
@date = date
end
end
def sort_libraries(libraries, key)
return libraries.map do |library|
library.attr_sort(:sort_by => key)
end
end
bobs_books = [Book.new("doe", Time.now + 5000000), Book.new("ajay", Time.now), Book.new("johnson", Time.now + 2592000)]
marys_books = [Book.new("jackson", Time.now + 3000000), Book.new("coe", Time.now), Book.new("coe", Time.now + 2592000)]
toms_books = [Book.new("lola", Time.now + 2000000), Book.new("loe", Time.now), Book.new("black", Time.now + 2592000)]
sorted_libraries = sort_libraries([bobs_books,marys_books,toms_books],[:author,:date])
require 'pp'
pp bobs_books.attr_sort(:sort_by => [:author,:date])
puts
pp marys_books.attr_sort(:sort_by => [:author,:date])
puts
pp toms_books.attr_sort(:sort_by => [:author,:date])
puts
puts
pp sorted_libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment