Module: MoreCoreExtensions::ObjectNamespace
- Defined in:
- lib/more_core_extensions/core_ext/object/namespace.rb
Instance Method Summary collapse
-
#in_namespace?(val) ⇒ Boolean
Returns whether or not the object is in the given namespace.
Instance Method Details
#in_namespace?(val) ⇒ Boolean
Returns whether or not the object is in the given namespace.
Aaa::Bbb::Ccc::Ddd.in_namespace?(Aaa::Bbb) #=> true
Aaa::Bbb::Ccc::Ddd.new.in_namespace?(Aaa::Bbb) #=> true
Aaa::Bbb::Ccc::Eee.in_namespace?("Aaa::Bbb") #=> true
Aaa::Bbb::Ccc::Eee.in_namespace?(Aaa::Bbb::Ccc::Ddd) #=> false
12 13 14 15 |
# File 'lib/more_core_extensions/core_ext/object/namespace.rb', line 12 def in_namespace?(val) val_ns = val.to_s.split("::") val_ns == (kind_of?(Module) ? namespace : self.class.namespace)[0, val_ns.length] end |