Skip to content

Instantly share code, notes, and snippets.

@JiriChara
Created January 13, 2013 20:36
Show Gist options
  • Save JiriChara/4526107 to your computer and use it in GitHub Desktop.
Save JiriChara/4526107 to your computer and use it in GitHub Desktop.
Parsing IRC messages in Ruby
result = {}
parts = message.split(' ')
result[:prefix] = parts.shift.gsub(/^:/, "") if parts[0] =~ /^:/
result[:command] = parts.shift
result[:params] = parts.take_while { |x| x[0] != ":" }
if result[:params].size < parts.size
full_string = parts.slice(result[:params].size..-1).join(" ")
full_string.gsub!(/^:/, "")
result[:params] << full_string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment