Reputation: 7809
How do I get the domain from an email-adress in ruby?
Upvotes: 42
Views: 18840
Reputation: 188054
Given the invariant that your input string is a valid email address, you could just write:
>> "[email protected]".split("@").last
=> "mycorp.com"
Upvotes: 84
Reputation: 17408
If you prefer using a library dedicated to understanding these things:
→ irb -rmail
ruby-1.9.2-p0 > Mail::Address.new('[email protected]').domain
=> "example.com"
Upvotes: 51