module Speculation::NamespacedSymbols

Public Class Methods

namespace(sym) click to toggle source
# File lib/speculation/namespaced_symbols.rb, line 32
def self.namespace(sym)
  parts = sym.to_s.split("/")
  parts.first if parts.count == 2
end
namespaced_name(sym) click to toggle source
# File lib/speculation/namespaced_symbols.rb, line 28
def self.namespaced_name(sym)
  sym.to_s.split("/").last
end
symbol(ns, name) click to toggle source
# File lib/speculation/namespaced_symbols.rb, line 22
def self.symbol(ns, name)
  ns = ns.name if ns.is_a?(Module)

  :"#{ns}/#{name}"
end

Public Instance Methods

ns(name_or_namespace, name = nil) click to toggle source

@param [#to_s] namespace @param [#to_s] name @return [Symbol] concatenation of `namespace` and `name` @example

ns(Foo::Bar, :foo)
# => :"Foo::Bar/baz"
# 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 : self.class
  end

  NamespacedSymbols.symbol(namespace, name)
end