A few methods about hostnames.
(in a mixin... could be helpful somewhere else later)
Constants
| IP_REGEX | = | /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ | Matching a classical IP address (not a v6 though). Should be sufficient for now. |
Public instance methods
split_host
(host)
Returns a pair host/domain, note that the domain starts with a dot.
split_host('localhost') --> [ 'localhost', nil ]
split_host('benz.car.co.nz') --> [ 'benz', '.car.co.nz' ]
split_host('127.0.0.1') --> [ '127.0.0.1', nil ]
split_host('::1') --> [ '::1', nil ]
[show source]
# File lib/rufus/verbs/cookies.rb, line 241 241: def split_host (host) 242: 243: return [ host, nil ] if IP_REGEX.match host 244: i = host.index('.') 245: return [ host, nil ] unless i 246: [ host[0..i-1], host[i..-1] ] 247: end