# Class Names

**URL:** <https://www.ruby-forum.com/t/class-names/95994>\
**Category:** Ruby\
**Created:** [June 22, 2006, 1:02am UTC](https://www.ruby-forum.com/t/class-names/95994 "2006-06-22T01:02:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 22, 2006, 1:02am UTC](https://www.ruby-forum.com/t/class-names/95994/1 "2006-06-22T01:02:50Z")

</div>

Hi, I was wondering how I can reffer to a class outside of my class, but  
it has the same name. Hopefully the following code will make it more  
clear:

module Test  
class File  
def print\_file  
# I don’t want to call Test::File.open here:  
File.open(‘test.rb’, “r”) { |f| puts f.read }  
end  
end  
end

Test::File.new().print\_file

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 22, 2006, 1:03am UTC](https://www.ruby-forum.com/t/class-names/95994/2 "2006-06-22T01:03:01Z")

</div>

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

> end  
> end
> 
> Test::File.new().print\_file

Prefix with ::, eg ::File.open.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 22, 2006, 1:06am UTC](https://www.ruby-forum.com/t/class-names/95994/3 "2006-06-22T01:06:10Z")

</div>

Aaron P. wrote:

> Hi, I was wondering how I can reffer to a class outside of my class, but  
> it has the same name. Hopefully the following code will make it more  
> clear:
> 
> module Test  
> class File  
> def print\_file  
> # I don’t want to call Test::File.open here:  
> File.open(‘test.rb’, “r”) { |f| puts f.read }

```
    ::File.open('test.rb', "r") { |f| puts f.read }

```

The :: means look up the constant in the top level scope.

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 22, 2006, 1:06am UTC](https://www.ruby-forum.com/t/class-names/95994/4 "2006-06-22T01:06:41Z")

</div>

On Thu, Jun 22, 2006 at 08:01:48AM +0900, Phillip H. wrote:

> Prefix with ::, eg ::File.open.

Perfect. Thank you!

–Aaron

---

<div class="post-metadata">

**Author:** ![aaronpowell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7bcc69/32.png) [@aaronpowell](https://www.ruby-forum.com/u/aaronpowell)\
**Post date:** [June 22, 2006, 1:06am UTC](https://www.ruby-forum.com/t/class-names/95994/5 "2006-06-22T01:06:24Z")

</div>

Aaron P. wrote:

> Hi, I was wondering how I can reffer to a class outside of my class, but  
> it has the same name. Hopefully the following code will make it more  
> clear:
> 
> module Test  
> class File  
> def print\_file  
> # I don’t want to call Test::File.open here:  
> File.open(‘test.rb’, “r”) { |f| puts f.read }

::File.open(‘test.rb’, “r”) { |f| puts f.read }

> ```
> end
> 
> ```
> 
> end  
> end
> 
> Test::File.new().print\_file

HTH,  
Dave
