Skip to content

Instantly share code, notes, and snippets.

@rdammkoehler
Created September 30, 2011 04:04
Show Gist options
  • Select an option

  • Save rdammkoehler/1252611 to your computer and use it in GitHub Desktop.

Select an option

Save rdammkoehler/1252611 to your computer and use it in GitHub Desktop.
So I worked this out for something at work, but I'm concerned it isn't readable. What do you think?
require 'set'
class FileParser
def initialize filename
@set = IO.readlines(filename).collect{ |s| s.split(',').map!{ |t| t.strip } }.flatten.to_set
end
def match? value
@set.include? value
end
end
@rdammkoehler

Copy link
Copy Markdown
Author

So I ended up with this, after your comments;

def initialize csv_filename
    lines = IO.readlines(csv_filename)
    lines.collect!{ |s| s.split(',') }
    lines.flatten!
    lines.map!{ |t| t.strip }
    @set = lines.to_set
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment