Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class KeyValuePairs
- # Take a file like:
- # G6C=24034
- # H9E=24049
- # and create the hash you'd expect
- # if instead you have something like:
- # G6C=24034,24036
- # H9E=24049
- # then use a block to do the specify the value
- def self.hash(file_name, separator='=', &block)
- contents = IO.readlines(file_name)
- contents.inject({}) do |memo,e|
- key,val = e.chomp.split(separator)
- if block_given?
- yield memo, key, val
- else
- memo[key] = val
- end
- memo
- end
- end
- end
Add Comment
Please, Sign In to add comment