Class: Rasti::App::Utils
- Inherits:
-
Object
- Object
- Rasti::App::Utils
- Defined in:
- lib/rasti/app/utils.rb
Class Method Summary collapse
- .classes_in(namespace, superclass = nil) ⇒ Object
- .namespace_of(klass) ⇒ Object
- .split_hash(hash, keys) ⇒ Object
Class Method Details
.classes_in(namespace, superclass = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rasti/app/utils.rb', line 6 def classes_in(namespace, superclass=nil) [].tap do |classes| namespace.constants.each do |name| constant = namespace.const_get name if constant.class == Module classes_in(constant, superclass).each { |c| classes << c } elsif constant.class == Class && (superclass.nil? || constant.ancestors.include?(superclass)) classes << constant end end end end |
.namespace_of(klass) ⇒ Object
19 20 21 22 |
# File 'lib/rasti/app/utils.rb', line 19 def namespace_of(klass) namespace = klass.name.split('::')[0..-2].join('::') namespace.empty? ? nil : Object.const_get(namespace) end |
.split_hash(hash, keys) ⇒ Object
24 25 26 |
# File 'lib/rasti/app/utils.rb', line 24 def split_hash(hash, keys) [hash.slice(*keys), hash.slice(*(hash.keys - keys))] end |