Search code examples
ruby-on-railsruby

How to get domain from email


How do I get the domain from an email-adress in ruby?


Solution

  • Given the invariant that your input string is a valid email address, you could just write:

    >> "[email protected]".split("@").last
    => "mycorp.com"