2 # Splits the rightmost part of a string using '::' as delimiter
3 # Returns an array of both parts or nil if either is empty.
4 # An empty rightmost part is ignored and converted as 'string::' => 'string'
7 # "foo" -> ["foo", nil]
8 # "foo::" -> ["foo", nil]
9 # "foo::bar" -> ["foo", "bar"]
10 # "foo::bar::" -> ["foo", "bar"]
11 # "::foo" -> [nil, "foo"]
12 # "::foo::" -> [nil, "foo"]
13 # "foo::bar::baz" -> ["foo::bar", "baz"]
14 # "foo::bar::baz::" -> ["foo::bar", "baz"]
16 def self.split_domain(str)
17 left, right = nil, nil
19 left, delimiter, right = str.gsub(/::$/, '').rpartition('::')
20 left, right = right, nil if delimiter.empty?
21 left = nil if left.empty?