module ActionDispatch::Http::URL
def extract_subdomains(host, tld_length)
# Second-level domain example
extract_subdomains('www.example.com', 1) # => ["www"]
# Top-level domain example
Returns the subdomains of a host as an Array given the domain level.
def extract_subdomains(host, tld_length) if named_host?(host) extract_subdomains_from(host, tld_length) else [] end end