# Log4r and Ruby 1.8.0 in Singleton problems

**URL:** <https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224>\
**Category:** ruby-talk\
**Created:** [5 August 2003 10:17 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224 "2003-08-05T10:17:55Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Heinemeier\_Ha2](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@David\_Heinemeier\_Ha2](https://rubytalk.org/u/David_Heinemeier_Ha2)\
**Post date:** [5 August 2003 10:17 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/1 "2003-08-05T10:17:55Z")

</div>

Somethings rotten…

david% irb  
irb(main):001:0\> require 'Singleton’  
irb(main):002:0\> class Something  
irb(main):003:1\> include Singleton  
irb(main):004:1\> end  
irb(main):005:0\> require ‘log4r’  
/usr/local/lib/ruby/1.8/singleton.rb:119: warning: already initialized  
constant FirstInstanceCall  
NameError: undefined method `extend_object' for`Singleton’  
from /usr/local/lib/ruby/1.8/singleton.rb:161:in `undef_method' from /usr/local/lib/ruby/1.8/singleton.rb:161 from /usr/local/lib/ruby/site_ruby/1.8/log4r/repository.rb:4:in`require’  
from /usr/local/lib/ruby/site\_ruby/1.8/log4r/repository.rb:4  
from  
/usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/  
outputterfactory.rb:5:in `require' from /usr/local/lib/ruby/site_ruby/1.8/log4r/outputter/outputterfactory.rb:5 from /usr/local/lib/ruby/site_ruby/1.8/log4r/outputter/outputter.rb:10:in`require’  
from  
/usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/outputter.rb:10  
from  
/usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/iooutputter.rb:2:in  
`require' from /usr/local/lib/ruby/site_ruby/1.8/log4r/outputter/iooutputter.rb:2 from /usr/local/lib/ruby/site_ruby/1.8/log4r/outputter/fileoutputter.rb:4:in`require’  
from  
/usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/fileoutputter.rb:4  
from /usr/local/lib/ruby/site\_ruby/1.8/log4r.rb:8:in `require' from /usr/local/lib/ruby/site_ruby/1.8/log4r.rb:8 from (irb):5:in`require’  
from (irb):5  
from  
/usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/  
outputter.rb:118irb(main):006:0\>

It doens’t do this unless I make another Singleton-class first. Any got  
a clue?

> **···**
>
> –  
> David Heinemeier Hansson,  
> [http://www.loudthinking.com/](http://www.loudthinking.com/) – Thoughts for free  
> [http://www.nextangle.com/](http://www.nextangle.com/) – Thoughts for hire

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [5 August 2003 10:38 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/2 "2003-08-05T10:38:20Z")

</div>

> irb(main):001:0\> require 'Singleton'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^^^^

What is this module ?

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Christoph1](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@Christoph1](https://rubytalk.org/u/Christoph1)\
**Post date:** [5 August 2003 14:39 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/3 "2003-08-05T14:39:20Z")

</div>

David Heinemeier Hansson wrote:

> Somethings rotten…
> 
> david% irb  
> irb(main):001:0\> require ‘Singleton’  
> irb(main):002:0\> class Something  
> irb(main):003:1\> include Singleton  
> irb(main):004:1\> end  
> irb(main):005:0\> require ‘log4r’  
> /usr/local/lib/ruby/1.8/singleton.rb:119: warning: already initialized  
> constant FirstInstanceCall  
> NameError: undefined method `extend_object' for `Singleton’

On windows you will get the same error message. However, if you  
write

> **···**
>
> * * *
> 
> ## require ‘singleton’ class A include Singleton end require ‘log4r’
> 
> you’ll be fine. My guess is that ruby `thinks'' that `Singleton.rb"  
> and `singleton.rb" (in my case installed in E:/Ruby/lib/ruby/1.8) are different files - however in the windows world or on a Macs HFS+ file-system `Singleton.rb" and ``singleton.rb’’ refer to the  
> same file.
> 
> This difference results in unnecessary reload of ``singleton.rb’’  
> which in turn triggers the NameError of Ruby trying to undefine  
> an already undefined method (extend\_object).
> 
> I suggest that you consistently use the lower case version require  
> ‘singleton’. Alternatively change the line
> 
> 161 \> undef\_method :extend\_object
> 
> in singleton.rb to
> 
> 161 \> undef\_method :extend\_object unless defined? :extend\_object
> 
> /Christoph

---

<div class="post-metadata">

**Author:** ![David\_Heinemeier\_Ha2](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@David\_Heinemeier\_Ha2](https://rubytalk.org/u/David_Heinemeier_Ha2)\
**Post date:** [5 August 2003 10:51 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/4 "2003-08-05T10:51:40Z")

</div>

> > irb(main):001:0\> require ‘Singleton’  
> > ^^^^^^^^^
> 
> What is this module ?

I’m sorry. I recreated the test case too quickly (and wrong). Here’s a  
better one:

log4r.rbx:

require ‘log4r’

Log = Log4r::Logger.new(“AC”)  
Log.add Log4r::StderrOutputter.new ‘console’

…which produce:

/usr/local/lib/ruby/1.8/singleton.rb:161:in `undef_method': undefined method `extend\_object’ for `Singleton' (NameError) from /usr/local/lib/ruby/1.8/singleton.rb:161 from /usr/local/lib/ruby/1.8/auto-reload.rb:77:in `load’  
from /usr/local/lib/ruby/1.8/auto-reload.rb:77:in `require' from /usr/local/lib/ruby/site_ruby/1.8/log4r/repository.rb:4 from /usr/local/lib/ruby/1.8/auto-reload.rb:77:in `load’  
from /usr/local/lib/ruby/1.8/auto-reload.rb:77:in `require' from /usr/local/lib/ruby/site_ruby/1.8/log4r/outputter/outputterfactory.rb:5 from /usr/local/lib/ruby/1.8/auto-reload.rb:77:in `load’  
… 12 levels…  
from /usr/local/lib/ruby/1.8/auto-reload.rb:77:in `require' from /Users/david/Sites/extranet/log4r.rbx:1 from /usr/local/lib/ruby/1.8/apache/ruby-run.rb:53:in `load’  
from /usr/local/lib/ruby/1.8/apache/ruby-run.rb:53:in `handler’

The contents of log4r.rbx works fine if used in IRB, but not under  
mod\_ruby.

/ David

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [5 August 2003 11:01 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/5 "2003-08-05T11:01:01Z")

</div>

> log4r.rbx:

ruby is trying to load \*twice\* the same module 'singleton.rb' : it do this  
because it don't have the same path, or name, or version, for singleton.rb

svg% cat b.rb  
#!/usr/bin/ruby  
require 'singleton'  
class Something  
&nbsp;&nbsp;&nbsp;include Singleton  
end  
require 'log4r'  
svg%

svg% b.rb  
svg%

Now

svg% cat b.rb  
#!/usr/bin/ruby  
require '/usr/local/lib/ruby/1.8/singleton.rb'  
class Something  
&nbsp;&nbsp;&nbsp;include Singleton  
end  
require 'log4r'  
svg%

svg% b.rb  
/usr/local/lib/ruby/1.8/singleton.rb:119: warning: already initialized constant FirstInstanceCall  
/usr/local/lib/ruby/1.8/singleton.rb:161:in `undef_method': undefined method `extend\_object' for `Singleton' (NameError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/1.8/singleton.rb:161  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/repository.rb:4:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/repository.rb:4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/outputterfactory.rb:5:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/outputterfactory.rb:5  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/outputter.rb:10:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/outputter.rb:10  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/iooutputter.rb:2:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/iooutputter.rb:2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/fileoutputter.rb:4:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r/outputter/fileoutputter.rb:4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r.rb:8:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/log4r.rb:8  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from ./b.rb:6:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from ./b.rb:6  
svg%

For ruby

&nbsp;&nbsp;&nbsp;require '/usr/local/lib/ruby/1.8/singleton.rb'

is different (it think that it's another module)

&nbsp;&nbsp;&nbsp;require 'singleton' # which is in repository.rb

This is why it give an error

Another reason is that you mix  
&nbsp;&nbsp;&nbsp;\* ruby 1.8.0  
&nbsp;&nbsp;&nbsp;\* mod\_ruby built with ruby 1.6.8

Guy Decoux

---

<div class="post-metadata">

**Author:** ![David\_Heinemeier\_Ha2](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@David\_Heinemeier\_Ha2](https://rubytalk.org/u/David_Heinemeier_Ha2)\
**Post date:** [5 August 2003 11:22 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/6 "2003-08-05T11:22:39Z")

</div>

> For ruby
> 
> require ‘/usr/local/lib/ruby/1.8/singleton.rb’
> 
> is different (it think that it’s another module)
> 
> require ‘singleton’ # which is in repository.rb
> 
> This is why it give an error

Right. But the log4r.rbx doesn’t contain any requirements to include  
the singleton module more than once. It’s _only_ those three lines:

require ‘log4r’  
Log = Log4r::Logger.new(“AC”)  
Log.add Log4r::StderrOutputter.new ‘console’

…and since those three lines work just fine in IRB, I suspect  
something fishy with mod\_ruby.

> Another reason is that you mix
> 
> - ruby 1.8.0
> - mod\_ruby built with ruby 1.6.8

I didn’t. Just double-checked it and even recompiled mod\_ruby (1.1.1)  
and installed it again. It’s surely ruby 1.8.0 and mod\_ruby 1.1.1  
compiled with the same version.

(Thanks for the suggestions, though…)

/ David

---

<div class="post-metadata">

**Author:** ![Dave\_Mail\_Archive](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Dave\_Mail\_Archive](https://rubytalk.org/u/Dave_Mail_Archive)\
**Post date:** [5 August 2003 14:09 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/7 "2003-08-05T14:09:19Z")

</div>

ts wrote:

> For ruby
> 
> require ‘/usr/local/lib/ruby/1.8/singleton.rb’
> 
> is different (it think that it’s another module)
> 
> require ‘singleton’ # which is in repository.rb
> 
> This is why it give an error

I have never understood this: why doesn’t Ruby store the cannonical  
(fully expanded) path name; that would eliminate this kind of problem.

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [5 August 2003 11:43 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/8 "2003-08-05T11:43:52Z")

</div>

ruby 1.8.0 installs its libraries in a different place… so just to be  
sure, try  
puts RUBY\_VERSION  
in your mod\_ruby application and see what it reports.

Cheers,

Brian.

> **···**
>
> On Tue, Aug 05, 2003 at 08:22:39PM +0900, David Heinemeier Hansson wrote:
> 
> > > Another reason is that you mix
> > > 
> > > - ruby 1.8.0
> > > - mod\_ruby built with ruby 1.6.8
> > 
> > I didn’t. Just double-checked it and even recompiled mod\_ruby (1.1.1)  
> > and installed it again. It’s surely ruby 1.8.0 and mod\_ruby 1.1.1  
> > compiled with the same version.

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [5 August 2003 11:51 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/9 "2003-08-05T11:51:11Z")

</div>

> Right. But the log4r.rbx doesn't contain any requirements to include  
> the singleton module more than once. It's \_only\_ those three lines:

What is your complete configuration. I can reproduce it with auto-load

svg% ruby -rauto-reload -rlog4r -rsingleton -e 1  
/usr/local/lib/ruby/1.8/singleton.rb:119: warning: already initialized constant FirstInstanceCall  
/usr/local/lib/ruby/1.8/singleton.rb:161:in `undef_method': undefined method `extend\_object' for `Singleton' (NameError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/1.8/singleton.rb:161  
svg%

> I didn't. Just double-checked it and even recompiled mod\_ruby (1.1.1)  
> and installed it again. It's surely ruby 1.8.0 and mod\_ruby 1.1.1  
> compiled with the same version.

The apache server was restarted ?

Try to give it the command

&nbsp;&nbsp;&nbsp;&nbsp;HEAD / HTTP/1.0

to see what it say

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Marko\_Schulz](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@Marko\_Schulz](https://rubytalk.org/u/Marko_Schulz)\
**Post date:** [5 August 2003 14:35 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/10 "2003-08-05T14:35:02Z")

</div>

I always thought this isn’t done, so the programmer isn’t deluded a  
false sense of security: There isn’t always _the_ cannonical  
path. Think of filesystems that ignore the case in filenames. (Not to  
mention (symbolic and hard) links or alias names (single~1.rb)

> **···**
>
> On Tue, Aug 05, 2003 at 11:09:19PM +0900, Dave Thomas wrote:
> 
> > ts wrote:
> > 
> > > require ‘/usr/local/lib/ruby/1.8/singleton.rb’
> > > 
> > > is different (it think that it’s another module)
> > > 
> > > require ‘singleton’ # which is in repository.rb
> > 
> > I have never understood this: why doesn’t Ruby store the cannonical  
> > (fully expanded) path name; that would eliminate this kind of problem.
> 
> –  
> marko schulz

---

<div class="post-metadata">

**Author:** ![David\_Heinemeier\_Ha2](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@David\_Heinemeier\_Ha2](https://rubytalk.org/u/David_Heinemeier_Ha2)\
**Post date:** [5 August 2003 11:55 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/11 "2003-08-05T11:55:46Z")

</div>

> ruby 1.8.0 installs its libraries in a different place… so just to be  
> sure, try  
> puts RUBY\_VERSION  
> in your mod\_ruby application and see what it reports.

I’ve reduced the test case to this:

singleton.rbx:

require “singleton”

That doesn’t work (same complaining about trying to import the same  
class twice). This does, though:

require “/usr/local/lib/ruby/1.6/singleton.rb”

But “puts RUBY\_VERSION” from a .rbx gives me 1.8.0, so it must be  
running from the newest version. But mod\_ruby is obviously still using  
the 1.6 singleton.rb file. I just can’t figure out why.

/ David

---

<div class="post-metadata">

**Author:** ![David\_Heinemeier\_Ha2](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@David\_Heinemeier\_Ha2](https://rubytalk.org/u/David_Heinemeier_Ha2)\
**Post date:** [5 August 2003 12:05 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/12 "2003-08-05T12:05:27Z")

</div>

> What is your complete configuration. I can reproduce it with auto-load

OS X 10.2.6, mod\_ruby 1.1.1, Apache 1.3.27, ruby 1.8.0

> The apache server was restarted ?

Yearh. I even rebooted the entire machine.

> Try to give it the command
> 
> ```
> HEAD / HTTP/1.0
> 
> ```

HTTP/1.1 200 OK  
Server: Apache/1.3.27 (Darwin) mod\_ruby/1.1.1 PHP/4.3.2  
Content-Type: text/html

(Thanks again for helping me to locate this…)

/ David

> **···**
>
> Date: Tue, 05 Aug 2003 12:03:17 GMT

---

<div class="post-metadata">

**Author:** ![Dave\_Mail\_Archive](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Dave\_Mail\_Archive](https://rubytalk.org/u/Dave_Mail_Archive)\
**Post date:** [5 August 2003 14:46 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/13 "2003-08-05T14:46:07Z")

</div>

Marko Schulz wrote:

> > I have never understood this: why doesn’t Ruby store the cannonical  
> > (fully expanded) path name; that would eliminate this kind of problem.
> 
> I always thought this isn’t done, so the programmer isn’t deluded a  
> false sense of security: There isn’t always _the_ cannonical  
> path. Think of filesystems that ignore the case in filenames. (Not to  
> mention (symbolic and hard) links or alias names (single~1.rb)

1. Would it be worse than it is now?

2. Why couldn’t Ruby make the name cannonical. On a Unix-based box, for  
example, it could store the i-node number. Surely every operating system  
has _some_ way to get to a single target identifier for a given file?

Cheers

Dave

---

<div class="post-metadata">

**Author:** ![Ben\_Giddings](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@Ben\_Giddings](https://rubytalk.org/u/Ben_Giddings)\
**Post date:** [5 August 2003 14:50 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/14 "2003-08-05T14:50:07Z")

</div>

I see the argument, but I don’t really like it. One thing I like about  
Java (which seems more OO than Ruby) is that when you import something,  
what you’re specifying is classes rather than files. I like this idea  
because the classes are what you really care about anyhow.

Another problem which is starting to pop up is versioning. In Perl you  
can require that what you’re using has a certain version number. This  
is a good “sanity check” when you’re using libraries which may  
fluctuate (like the CGI one for example).

Is it too late to come up with an alternative to ‘require’?

Ben

> **···**
>
> On Tuesday, August 5, 2003, at 10:35 AM, Marko Schulz wrote:
> 
> > On Tue, Aug 05, 2003 at 11:09:19PM +0900, Dave Thomas wrote:
> > 
> > > I have never understood this: why doesn’t Ruby store the cannonical  
> > > (fully expanded) path name; that would eliminate this kind of problem.
> > 
> > I always thought this isn’t done, so the programmer isn’t deluded a  
> > false sense of security: There isn’t always _the_ cannonical  
> > path. Think of filesystems that ignore the case in filenames. (Not to  
> > mention (symbolic and hard) links or alias names (single~1.rb)

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [5 August 2003 15:01 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/15 "2003-08-05T15:01:44Z")

</div>

> I see the argument, but I don’t really like it. One thing I like about  
> Java (which seems more OO than Ruby) is that when you import something,  
> what you’re specifying is classes rather than files. I like this idea

Only because Java enforces a given directory structure. If you had the  
same constraint in Ruby, require would be similar to import.

> Is it too late to come up with an alternative to ‘require’?

Nothing prevents you from writing it, making it compatible with require  
and getting some people to use it 🙂

> **···**
>
> On Tue, Aug 05, 2003 at 11:50:07PM +0900, Ben Giddings wrote:
> 
> –  
> \_ \_
> 
> > > \_\_ \_\_ _| |_ \_\_\_ \_ \_\_ \_\_\_ \_\_ \_ \_ \_\_  
> > > '\_ \ / _`| __/__ | '_` \_ \ / ` | ’ \   
> > > ) | (| | |_\_\_ \ | | | | | (_| | | | |  
> > > .\_\_/ \_,_|\ __|__ /| |_| |_|\__,_|_| |\_|  
> > > Running Debian GNU/Linux Sid (unstable)  
> > > batsman dot geo at yahoo dot com
> 
> How do you power off this machine?  
> – Linus, when upgrading [linux.cs.helsinki.fi](http://linux.cs.helsinki.fi), and after using the machine for several months

---

<div class="post-metadata">

**Author:** ![Mark\_J\_Reed](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@Mark\_J\_Reed](https://rubytalk.org/u/Mark_J_Reed)\
**Post date:** [5 August 2003 15:19 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/16 "2003-08-05T15:19:29Z")

</div>

> > I always thought this isn’t done, so the programmer isn’t deluded a  
> > false sense of security: There isn’t always _the_ cannonical  
> > path. Think of filesystems that ignore the case in filenames. (Not to  
> > mention (symbolic and hard) links or alias names (single~1.rb)

> 1. Would it be worse than it is now?

Depends on whether you think false security is better than no  
security. 🙂

> 1. Why couldn’t Ruby make the name cannonical. On a Unix-based  
> box, for example, it could store the i-node number.

Technically, it would have to be the pair (device, i-node number),  
but it’s a good thought. If the file to be loaded has the same  
(d,i) as a file already loaded, don’t load it again. It would  
require more OS-specific code in the loader, though.

> Surely every operating system  
> has _some_ way to get to a single target identifier for a given file?

I would be wary of making such an assumption. It seems logical,  
but OSes are often illogical creatures, at least on the surface. 🙂

-Mark

> **···**
>
> On Tue, Aug 05, 2003 at 11:46:07PM +0900, Dave Thomas wrote:

---

<div class="post-metadata">

**Author:** ![Marko\_Schulz](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@Marko\_Schulz](https://rubytalk.org/u/Marko_Schulz)\
**Post date:** [5 August 2003 16:06 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/17 "2003-08-05T16:06:46Z")

</div>

> Marko Schulz wrote:
> 
> > > I have never understood this: why doesn’t Ruby store the cannonical  
> > > (fully expanded) path name; that would eliminate this kind of problem.
> > 
> > I always thought this isn’t done, so the programmer isn’t deluded a  
> > false sense of security: There isn’t always _the_ cannonical  
> > path. Think of filesystems that ignore the case in filenames. (Not to  
> > mention (symbolic and hard) links or alias names (single~1.rb)
> 
> 1. Would it be worse than it is now?

If there is a solution: Great!

I don’t really have enough cross-platform knowledge to decide whether  
it is possible; but on the platforms I know, it already seems awkward,  
to detect for sure, whether a file already has been read (maybe  
somebody should look how others do it):

> 1. Why couldn’t Ruby make the name cannonical. On a Unix-based box, for  
> example, it could store the i-node number.

Besides the number of the i-node you would at least have to store the  
mount point (or the device?). Here I have to files on different  
devices with the same inode:  
$ ls -di /usr/include/netax25 /home/marko/musik/Farin\_Urlaub/Endlich\_Urlaub  
374641 /home/marko/musik/Farin\_Urlaub/Endlich\_Urlaub  
374641 /usr/include/netax25

But even then, I wouldn’t be sure, that every filesystem on every  
unices uses reliable i-node numbers.

Under Linux they are at least not stable across remounts for a FAT-FS:

$ ls -i /mnt/dos/autoexec.bat  
67756 /mnt/dos/autoexec.bat  
$ sudo umount /mnt/dos/  
$ sudo mount /mnt/dos/  
$ ls -i /mnt/dos/autoexec.bat  
67757 /mnt/dos/autoexec.bat

> Surely every operating system  
> has _some_ way to get to a single target identifier for a given file?

Maybe just storing the full path is already enough (resolving all …/'s  
and maybe symlinks). Maybe storing a md5sum for each file is enough.  
Maybe somebody just has to try it.

> **···**
>
> On Tue, Aug 05, 2003 at 11:46:07PM +0900, Dave Thomas wrote:
> 
> –  
> marko schulz

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [5 August 2003 16:24 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/18 "2003-08-05T16:24:16Z")

</div>

> I don’t really have enough cross-platform knowledge to decide whether  
> it is possible; but on the platforms I know, it already seems awkward,  
> to detect for sure, whether a file already has been read (maybe  
> somebody should look how others do it):

In C, the file itself is responsible for this:

#ifndef \_myheader\_h  
#define \_myheader\_h  
… do stuff  
#endif

> Maybe storing a md5sum for each file is enough.

Cool idea, except the cost of reading in a file every time you see  
require ‘foo’  
means that it would break things. I quite happily put a ‘require’ buried  
inside a loop at the moment, knowing that the library will get read just the  
first time it’s needed.

Cheers,

Brian.

> **···**
>
> On Wed, Aug 06, 2003 at 01:06:46AM +0900, Marko Schulz wrote:

---

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [5 August 2003 22:55 UTC](https://rubytalk.org/t/log4r-and-ruby-1-8-0-in-singleton-problems/7224/19 "2003-08-05T22:55:10Z")

</div>

You would also need the constraint that files and classes be named  
the same. I am tending towards that constraint in my own code anyway,  
primarily so the target of ‘require’ resolves as a ctag, easing  
navigation.

Another difference between Java and Ruby here: Java allows only one  
“public” class in each file. Not that Ruby has the concept of  
packages anyway.

Gavin

> **···**
>
> On Wednesday, August 6, 2003, 1:01:44 AM, Mauricio wrote:
> 
> > On Tue, Aug 05, 2003 at 11:50:07PM +0900, Ben Giddings wrote:
> > 
> > > I see the argument, but I don’t really like it. One thing I like about  
> > > Java (which seems more OO than Ruby) is that when you import something,  
> > > what you’re specifying is classes rather than files. I like this idea
> 
> > Only because Java enforces a given directory structure. If you had the  
> > same constraint in Ruby, require would be similar to import.
