module ActionDispatch::Http::URL
def extract_subdomain(host, tld_length)
# Second-level domain example
extract_subdomain('www.example.com', 1) # => "www"
# Top-level domain example
Returns the subdomains of a host as a String given the domain level.
def extract_subdomain(host, tld_length) extract_subdomains(host, tld_length).join(".") end