module ActionDispatch::Http::URL

def extract_domain(host, tld_length)

extract_domain('dev.www.example.co.uk', 2) # => "example.co.uk"
# Second-level domain example
extract_domain('www.example.com', 1) # => "example.com"
# Top-level domain example

Returns the domain part of a host given the domain level.
def extract_domain(host, tld_length)
  extract_domain_from(host, tld_length) if named_host?(host)
end