# Class name methods

**URL:** <https://www.ruby-forum.com/t/class-name-methods/98023>\
**Category:** Ruby\
**Created:** [July 12, 2006, 1:06am UTC](https://www.ruby-forum.com/t/class-name-methods/98023 "2006-07-12T01:06:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@joey](https://www.ruby-forum.com/u/joey)\
**Post date:** [July 12, 2006, 1:06am UTC](https://www.ruby-forum.com/t/class-name-methods/98023/1 "2006-07-12T01:06:12Z")

</div>

Hey Ruby-Talk,  
I’ve got this:  
class H

end

def H(a)  
p a  
end  
H H

I was wondering how Ruby handles this? I know it works, but _how_?  
🙂

j`ey  
[http://www.eachmapinject.com](http://www.eachmapinject.com)  
Ergh C([http://code.eachmapinject.com/mountain\_signature.c](http://code.eachmapinject.com/mountain_signature.c)):

char n=‘#’,f=’ ‘;main(){char a[]={f,f,f,f,f,’\0’};  
printf(“\e[2J\e[H”);char \*t=a;int i=0,c=i;end:for(  
;(c==0?i++\<6:i–\>0);){c?\*t–=f:(\*t++=n);printf(“%s  
\n”,a);usleep(200000);};if(c==0){i=6;c=1;goto end;}}

---

<div class="post-metadata">

**Author:** ![joey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@joey](https://www.ruby-forum.com/u/joey)\
**Post date:** [July 12, 2006, 11:49am UTC](https://www.ruby-forum.com/t/class-name-methods/98023/2 "2006-07-12T11:49:52Z")

</div>

Joey schrieb:

> I was wondering how Ruby handles this? I know it works, but _how_?

Ruby has different namespaces for methods and constants, so you can  
create both a constant “H” and a method “H”. When parsing the expression

H H

Ruby notices that the first “H” is followed by a parameter, so Ruby  
chooses the _method_ “H”. The second “H” doesn’t have a parameter, so  
Ruby chooses the _constant_ “H”.

BTW, you can also do the same with methods and local variables:

v = “v”

def v(a)  
p a  
end

v v # =\> “v”

Note also the following error messages:

x y # =\> undefined local variable or method `y’

and

y = 1  
x y # =\> undefined method `x’

Here you see that “x” can only be a method, whereas “y” could be a local  
variable or a method.

Regards,  
Pit
