# Module#name for anonymous modules

**URL:** <https://www.ruby-forum.com/t/module-name-for-anonymous-modules/95995>\
**Category:** Ruby\
**Created:** [June 22, 2006, 1:09am UTC](https://www.ruby-forum.com/t/module-name-for-anonymous-modules/95995 "2006-06-22T01:09:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 22, 2006, 1:09am UTC](https://www.ruby-forum.com/t/module-name-for-anonymous-modules/95995/1 "2006-06-22T01:09:48Z")

</div>

Observation:

mod = Module.new  
mod.name #=\> “”

Maybe it would more friendly if Module#name returned nil in this case?  
Then one could more easily say:

if mod.name  
…  
end

T.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 22, 2006, 4:52am UTC](https://www.ruby-forum.com/t/module-name-for-anonymous-modules/95995/2 "2006-06-22T04:52:16Z")

</div>

Hi,

In message “Re: Module#name for anonymous modules”  
on Thu, 22 Jun 2006 08:08:20 +0900, removed\_email\_address@domain.invalid writes:

|Observation:  
|  
| mod = Module.new  
| mod.name #=\> “”  
|  
|Maybe it would more friendly if Module#name returned nil in this case?  
|Then one could more easily say:  
|  
| if mod.name  
| …  
| end

OK. It will be for 1.9 or later.

```
						matz.
```

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 22, 2006, 3:12pm UTC](https://www.ruby-forum.com/t/module-name-for-anonymous-modules/95995/3 "2006-06-22T15:12:45Z")

</div>

Yukihiro M. wrote:

> |Maybe it would more friendly if Module#name returned nil in this case?  
> |Then one could more easily say:  
> |  
> | if mod.name  
> | …  
> | end
> 
> OK. It will be for 1.9 or later.

Hmm, I think it may be too indirect. You aren’t really checking whether  
the module has a name or not, but rather if it’s anonymous. Maybe an  
#anonymous? method for both Module and Class, in addition to #name being  
nil?

Cheers,  
Daniel

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 22, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/module-name-for-anonymous-modules/95995/4 "2006-06-22T16:06:23Z")

</div>

Dimitri A. wrote:

> On 6/22/06, Daniel S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hmm, I think it may be too indirect. You aren’t really checking whether  
> > the module has a name or not, but rather if it’s anonymous.
> 
> Isn’t that the very definition of anonymous? “without a name”

Good point 🙂

I still think it’s less mysterious to users if they could check the  
anonymity of a module/class with an #anonymous? method, rather than  
checking whether the name is nil.

Cheers,  
Daniel

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 22, 2006, 3:25pm UTC](https://www.ruby-forum.com/t/module-name-for-anonymous-modules/95995/5 "2006-06-22T15:25:12Z")

</div>

On 6/22/06, Daniel S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hmm, I think it may be too indirect. You aren’t really checking whether  
> the module has a name or not, but rather if it’s anonymous.

Isn’t that the very definition of anonymous? “without a name”

🙂

- Dimitri
