How do I get the domain from an email-adress in ruby?
If you prefer using a library dedicated to understanding these things:
→ irb -rmail
ruby-1.9.2-p0 > Mail::Address.new('feep+wibble@example.com').domain
=> "example.com"
>> "hey@mycorp.com".split("@").last
=> "mycorp.com"
>> email = "Sahil Grover<sahil+test@stackoverflow.com>"
=> "Sahil Grover<sahil+test@stackoverflow.com>"
>> mail = Mail::Address.new(email)
=> #<Mail::Address:75152940 Address: |Sahil Grover <sahil+test@stackoverflow.com>| >
>> mail.instance_values
=> {"output_type"=>:decode,
"parsed"=>true,
"data"=>#<struct Mail::Parsers::AddressStruct
raw="Sahil Grover<sahil+test@stackoverflow.com>",
domain="stackoverflow.com",
comments=[],
local="sahil+test",
obs_domain_list=nil,
display_name="Sahil Grover",
group=nil,
error=nil>,
"display_name"=>"Sahil Grover"}
>> mail.domain
=> "stackoverflow.com"