From afd2e19be3b74effa3fdb9c4affd48f0aaede838 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 7 Feb 2010 23:03:13 +0100 Subject: removes Module#included_in_classes, which is no longer used --- .../active_support/core_ext/module/inclusion.rb | 30 ---------------------- 1 file changed, 30 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/module/inclusion.rb (limited to 'activesupport/lib/active_support/core_ext/module') diff --git a/activesupport/lib/active_support/core_ext/module/inclusion.rb b/activesupport/lib/active_support/core_ext/module/inclusion.rb deleted file mode 100644 index 4f23841645..0000000000 --- a/activesupport/lib/active_support/core_ext/module/inclusion.rb +++ /dev/null @@ -1,30 +0,0 @@ -class Module - # Returns the classes in the current ObjectSpace where this module has been - # mixed in according to Module#included_modules. - # - # module M - # end - # - # module N - # include M - # end - # - # class C - # include M - # end - # - # class D < C - # end - # - # p M.included_in_classes # => [C, D] - # - def included_in_classes - classes = [] - ObjectSpace.each_object(Class) { |k| classes << k if k.included_modules.include?(self) } - - classes.reverse.inject([]) do |unique_classes, klass| - unique_classes << klass unless unique_classes.collect { |k| k.to_s }.include?(klass.to_s) - unique_classes - end - end -end \ No newline at end of file -- cgit v1.2.3 From cf9a52a7b6a4cb28709f116b306e06395b40b752 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 7 Feb 2010 23:06:15 +0100 Subject: removes Module#as_load_path, which is no longer used --- .../lib/active_support/core_ext/module/loading.rb | 25 ---------------------- 1 file changed, 25 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/module/loading.rb (limited to 'activesupport/lib/active_support/core_ext/module') diff --git a/activesupport/lib/active_support/core_ext/module/loading.rb b/activesupport/lib/active_support/core_ext/module/loading.rb deleted file mode 100644 index 43d0578ae6..0000000000 --- a/activesupport/lib/active_support/core_ext/module/loading.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'active_support/core_ext/string/inflections' - -class Module - # Returns String#underscore applied to the module name minus trailing classes. - # - # ActiveRecord.as_load_path # => "active_record" - # ActiveRecord::Associations.as_load_path # => "active_record/associations" - # ActiveRecord::Base.as_load_path # => "active_record" (Base is a class) - # - # The Kernel module gives an empty string by definition. - # - # Kernel.as_load_path # => "" - # Math.as_load_path # => "math" - def as_load_path - if self == Object || self == Kernel - '' - elsif is_a? Class - parent == self ? '' : parent.as_load_path - else - name.split('::').collect do |word| - word.underscore - end * '/' - end - end -end \ No newline at end of file -- cgit v1.2.3 From b8bb54af7ff6652327d99f6a7cf5c96a3f3f876d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 11 Feb 2010 23:15:04 +0100 Subject: defines Module#anonymous? --- .../lib/active_support/core_ext/module/anonymous.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/module/anonymous.rb (limited to 'activesupport/lib/active_support/core_ext/module') diff --git a/activesupport/lib/active_support/core_ext/module/anonymous.rb b/activesupport/lib/active_support/core_ext/module/anonymous.rb new file mode 100644 index 0000000000..60d7d9410b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/module/anonymous.rb @@ -0,0 +1,20 @@ +class Module + # A module may or may not have a name. + # + # module M; end + # M.name # => "M" + # + # m = Module.new + # m.name # => "" + # + # A module gets a name when it is first assigned to a constant. Either + # via the +module+ or +class+ keyword or by an explicit assignment: + # + # m = Module.new # creates an anonymous module + # M = m # => m gets a name here as a side-effect + # m.name # => "M" + # + def anonymous? + name == '' + end +end -- cgit v1.2.3 From aa82bdf92953824fd35db4a734bf6effa8de3329 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 11 Feb 2010 23:41:16 +0100 Subject: moves Class#reachable? to Module#reachable?, bases implementation on anonymous? and constantize, and adds test coverage --- activesupport/lib/active_support/core_ext/module/reachable.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/module/reachable.rb (limited to 'activesupport/lib/active_support/core_ext/module') diff --git a/activesupport/lib/active_support/core_ext/module/reachable.rb b/activesupport/lib/active_support/core_ext/module/reachable.rb new file mode 100644 index 0000000000..443d2c3d53 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/module/reachable.rb @@ -0,0 +1,10 @@ +require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/string/inflections' + +class Module + def reachable? #:nodoc: + !anonymous? && name.constantize.equal?(self) + rescue NameError + false + end +end -- cgit v1.2.3 From a506bac58616db2dc2b470a2416deed398645916 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 11 Feb 2010 23:58:15 +0100 Subject: fixes Module#anonymous? for 1.9 --- activesupport/lib/active_support/core_ext/module/anonymous.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/module') diff --git a/activesupport/lib/active_support/core_ext/module/anonymous.rb b/activesupport/lib/active_support/core_ext/module/anonymous.rb index 60d7d9410b..df25a09ec9 100644 --- a/activesupport/lib/active_support/core_ext/module/anonymous.rb +++ b/activesupport/lib/active_support/core_ext/module/anonymous.rb @@ -1,4 +1,6 @@ -class Module +require 'active_support/core_ext/object/blank' + +class Module # A module may or may not have a name. # # module M; end @@ -15,6 +17,8 @@ class Module # m.name # => "M" # def anonymous? - name == '' + # Uses blank? because the name of an anonymous class is an empty + # string in 1.8, and nil in 1.9. + name.blank? end end -- cgit v1.2.3