class Subdomain class self def instance _instance self new end def met

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Subdomain
class << self
def instance
@_instance ||= self.new
end
def method_missing(meth, *args, &block)
if [:match, :domain, :domain=].include? meth
instance.send meth, *args
else
super
end
end
end
attr_accessor :domain
def match(subdomain)
if !subdomain
cast_subdomain nil
else
{subdomain: cast_subdomain(subdomain)}
end
end
private
def cast_subdomain(subdomain)
if domain.nil?
subdomain
else
'' << subdomain << '.' << domain.split('.')[0..-3].join('.')
end
end
end