aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-02-14 19:28:05 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-02-14 19:28:05 +0000
commit6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3 (patch)
tree3da8d75101aabe3c1d90d0582505ec1480c9d885 /activesupport/lib/active_support/core_ext/module
parent77bf78b3b78a41d4f2f6e733f5c9c00608c0adba (diff)
parenta1b60696e2b13cbe94d748444cc0da37b190fbb8 (diff)
downloadrails-6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3.tar.gz
rails-6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3.tar.bz2
rails-6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3.zip
Merge remote branch 'mainstream/master'
Conflicts: railties/README railties/guides/source/active_support_core_extensions.textile railties/guides/source/getting_started.textile railties/lib/generators/rails/app/templates/README
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module')
-rw-r--r--activesupport/lib/active_support/core_ext/module/anonymous.rb24
-rw-r--r--activesupport/lib/active_support/core_ext/module/inclusion.rb30
-rw-r--r--activesupport/lib/active_support/core_ext/module/loading.rb25
-rw-r--r--activesupport/lib/active_support/core_ext/module/reachable.rb10
4 files changed, 34 insertions, 55 deletions
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..df25a09ec9
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/anonymous.rb
@@ -0,0 +1,24 @@
+require 'active_support/core_ext/object/blank'
+
+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?
+ # 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
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
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
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