Skip to content

Instantly share code, notes, and snippets.

@codatory
Created June 21, 2012 00:51
Show Gist options
  • Select an option

  • Save codatory/2963226 to your computer and use it in GitHub Desktop.

Select an option

Save codatory/2963226 to your computer and use it in GitHub Desktop.
Ruby Class for creating a list of normalized strings
require 'set'
class CleanedList
def initialize
@data = SortedSet.new
end
def to_a
@data.to_a
end
def to_set
@data
end
def <<(item)
processed = item.to_s.downcase.strip.gsub(/\s{2,}/, '')
@data << processed unless processed.nil? || processed == ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment