# Dir.bitbucket?

**URL:** <https://www.ruby-forum.com/t/dir-bitbucket/65647>\
**Category:** Ruby\
**Created:** [August 20, 2006, 6:36am UTC](https://www.ruby-forum.com/t/dir-bitbucket/65647 "2006-08-20T06:36:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 20, 2006, 6:36am UTC](https://www.ruby-forum.com/t/dir-bitbucket/65647/1 "2006-08-20T06:36:16Z")

</div>

Hi all,

Occasionally I have to do something like this:

bitbucket = RUBY\_PLATFORM.match(‘mswin’) ? ‘NUL’ : ‘/dev/null’

How about a Dir.bitbucket method? Or Dir.null, or whatever you want to  
call it.

I think the code, using pure Ruby, would look like this:

case RUBY\_PLATFORM  
when /mswin/i  
‘NUL’  
when /amiga/i  
‘NIL:’  
when /openvms/i  
‘NL:’  
else  
‘/dev/null’  
end

I based this on [Null device - Wikipedia](http://en.wikipedia.org/wiki//dev/null)

Useful? If so, we could easily patch dir.c, though I’m not sure what  
the best way to approach it would be, i.e. should we do platform checks  
within the code or rely on constants set during the build phase?

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 20, 2006, 7:12am UTC](https://www.ruby-forum.com/t/dir-bitbucket/65647/2 "2006-08-20T07:12:19Z")

</div>

On Aug 19, 2006, at 11:34 PM, Daniel B. wrote:

> Hi all,
> 
> Occasionally I have to do something like this:
> 
> bitbucket = RUBY\_PLATFORM.match(‘mswin’) ? ‘NUL’ : ‘/dev/null’
> 
> How about a Dir.bitbucket method? Or Dir.null, or whatever you want  
> to call it.

it’s not quite the same thing, since it’s not a part of the Ruby  
core, but I’ve got a library, Facter[1], specifically meant to help  
handle this kind of platform variety. This kind of simple code would  
look like this:

Facter.add :bitbucket do  
setcode do  
case Facter.operatingsystem  
when /mswin/i: ‘NUL’  
when /amiga/i: ‘NIL’  
when /openvms/i: ‘NL:’  
else  
‘/dev/null’  
end  
end  
end

The reason the code is set separately is that, for more complicated  
facts, you could have a separate resolution mechanism for every  
platform:

Facter.add :bitbucket do  
confine :operatingsystem =\> :mswin  
setcode { “NUL” } # strings get executed as shell code, so you have  
to use a block  
end

Facter.add :bitbucket do  
confine :operatingsystem =\> :amiga  
setcode { “NIL” }  
end  
…

Any fact can be be confined based on other facts, so you could  
confine a fact to work only on a given release of a specific platform  
(e.g., Mac OS X seems to change the config file that stores the IP  
configuration on every release).

The interface could probably be slimmed down some, but the basic idea  
is there: Make it simple to get a fact on different platforms. It’s  
especially useful for things like domain names, which can often be  
resolved multiple ways (/etc/resolv.conf, /bin/domainname, dns, /etc/  
hosts, etc.)

1 - [http://reductivelabs.com/projects/facter](http://reductivelabs.com/projects/facter)
