Skip to content

Commit

Permalink
Module#name returns nil for anonymous class in ruby 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nashby committed Dec 25, 2011
1 parent bd91154 commit 9e0f5ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions activesupport/lib/active_support/core_ext/module/anonymous.rb
@@ -1,13 +1,11 @@
require 'active_support/core_ext/object/blank'

class Module class Module
# A module may or may not have a name. # A module may or may not have a name.
# #
# module M; end # module M; end
# M.name # => "M" # M.name # => "M"
# #
# m = Module.new # m = Module.new
# m.name # => "" # m.name # => nil
# #
# A module gets a name when it is first assigned to a constant. Either # 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: # via the +module+ or +class+ keyword or by an explicit assignment:
Expand All @@ -17,8 +15,6 @@ class Module
# m.name # => "M" # m.name # => "M"
# #
def anonymous? def anonymous?
# Uses blank? because the name of an anonymous class is an empty name.nil?
# string in 1.8, and nil in 1.9.
name.blank?
end end
end end
Expand Up @@ -822,7 +822,7 @@ M.name # => "M"
N = Module.new N = Module.new
N.name # => "N" N.name # => "N"


Module.new.name # => "" in 1.8, nil in 1.9 Module.new.name # => nil
</ruby> </ruby>


You can check whether a module has a name with the predicate +anonymous?+: You can check whether a module has a name with the predicate +anonymous?+:
Expand Down

0 comments on commit 9e0f5ac

Please sign in to comment.