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? --- activesupport/lib/active_support/core_ext/module.rb | 2 +- .../lib/active_support/core_ext/module/anonymous.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 activesupport/lib/active_support/core_ext/module/anonymous.rb (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index 41600929f4..c907445d90 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -1,6 +1,6 @@ require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/introspection' - +require 'active_support/core_ext/module/anonymous' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' 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