Sha256: d36b3d3ebd814f5fa5925db8304e22880152f71425b9d3523cf1dee04024567b
Contents?: true
Size: 750 Bytes
Versions: 2
Compression:
Stored size: 750 Bytes
Contents
module Sortify def sort_option(name, body) @sort_options ||= [] name = name.to_sym begin scope name, body rescue ArgumentError => e raise e else @sort_options << name end end def default_sort_option(name) @default_sort_option = name.to_sym end def sort_options return @sort_options end def sortify(sort_option = "") sort_option = sort_option.to_sym unless sort_option == nil if @sort_options.include? sort_option self.send(sort_option) else begin self.send(@default_sort_option) rescue raise NoMethodError, "The default sort option you provided, '#{@default_sort_option.to_s}' does not exist." end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sortify-0.1.3 | lib/sortify.rb |
sortify-0.1.2 | lib/sortify.rb |