Permalink
Browse files

Merge pull request #4185 from nashby/module-anonymous

Module#name returns nil for anonymous class in ruby 1.9
  • Loading branch information...
2 parents bd91154 + 9e0f5ac commit 819ea5f9af83b5a427e94c178a419fd327bf37d9 @fxn fxn committed Dec 25, 2011
View
8 activesupport/lib/active_support/core_ext/module/anonymous.rb
@@ -1,13 +1,11 @@
-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 # => ""
+ # m.name # => nil
#
# 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:
@@ -17,8 +15,6 @@ class Module
# 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?
+ name.nil?
end
end
View
2 railties/guides/source/active_support_core_extensions.textile
@@ -822,7 +822,7 @@ M.name # => "M"
N = Module.new
N.name # => "N"
-Module.new.name # => "" in 1.8, nil in 1.9
+Module.new.name # => nil
</ruby>
You can check whether a module has a name with the predicate +anonymous?+:

0 comments on commit 819ea5f

Please sign in to comment.