Module: Speculation::NamespacedSymbols

Included in:
Speculation, Test
Defined in:
lib/speculation/namespaced_symbols.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.name(sym) ⇒ Object



26
27
28
# File 'lib/speculation/namespaced_symbols.rb', line 26

def self.name(sym)
  sym.to_s.split("/").last
end

.namespace(sym) ⇒ Object



30
31
32
33
# File 'lib/speculation/namespaced_symbols.rb', line 30

def self.namespace(sym)
  parts = sym.to_s.split("/")
  parts.first if parts.count == 2
end

.symbol(ns, name) ⇒ Object



22
23
24
# File 'lib/speculation/namespaced_symbols.rb', line 22

def self.symbol(ns, name)
  :"#{ns}/#{name}"
end

Instance Method Details

#ns(name_or_namespace, name = nil) ⇒ Symbol

Returns concatenation of ‘namespace` and `name`.

Examples:

ns(Foo::Bar, :foo)
# => :"Foo::Bar/baz"

Parameters:

  • namespace (#to_s)
  • name (#to_s) (defaults to: nil)

Returns:

  • (Symbol)

    concatenation of ‘namespace` and `name`



11
12
13
14
15
16
17
18
19
20
# File 'lib/speculation/namespaced_symbols.rb', line 11

def ns(name_or_namespace, name = nil)
  if name
    namespace = name_or_namespace
  else
    name = name_or_namespace
    namespace = is_a?(Module) ? self.name : self.class.name
  end

  NamespacedSymbols.symbol(namespace, name)
end