Module: GetText::ClassInfo
- Includes:
- Locale::Util::Memoizable
- Defined in:
- lib/gettext/class_info.rb
Class Method Summary collapse
-
.normalize_class(klass) ⇒ Object
normalize the klass name.
-
.related_classes(klass, all_classes = []) ⇒ Object
Returns the classes which related to klass (klass’s ancestors, included modules and nested modules).
-
.related_classes_internal(klass, all_classes = [], analyzed_classes = []) ⇒ Object
Internal method for related_classes.
Class Method Details
.normalize_class(klass) ⇒ Object
normalize the klass name
9 10 11 12 13 14 15 |
# File 'lib/gettext/class_info.rb', line 9 def normalize_class(klass) ret = (klass.kind_of? Module) ? klass : klass.class if ret.name =~ /^\#<|^$/ or ret == GetText ret = Object end ret end |
.related_classes(klass, all_classes = []) ⇒ Object
Returns the classes which related to klass (klass’s ancestors, included modules and nested modules)
48 49 50 51 |
# File 'lib/gettext/class_info.rb', line 48 def (klass, all_classes = []) ret = (klass, all_classes) (ret + [Object]).uniq end |
.related_classes_internal(klass, all_classes = [], analyzed_classes = []) ⇒ Object
Internal method for related_classes.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gettext/class_info.rb', line 18 def (klass, all_classes = [], analyzed_classes = [] ) ret = [] klass = normalize_class(klass) return [Object] if [Object, Kernel].include? klass ary = klass.name.split(/::/) while(v = ary.shift) ret.unshift(((ret.size == 0) ? Object.const_get(v) : ret[0].const_get(v))) end ret -= analyzed_classes if ret.size > 1 ret += (ret[1], all_classes, analyzed_classes) ret.uniq! end analyzed_classes << klass unless analyzed_classes.include? klass klass.ancestors[1..-1].each do |v| ret += (v, all_classes, analyzed_classes) ret.uniq! end if all_classes.size > 0 ((ret - [Kernel]) & all_classes).uniq else (ret - [Kernel]).uniq end end |