The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Fun with File.join

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Fun with File.join Posted: Aug 26, 2005 9:52 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Fun with File.join
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
I love testing edge cases. It's fun to see what happens. Really, it's a perverse desire I have to see if I can make the Ruby interpreter segfault.

So, today I decided to start mucking around with File.join. What what you expect from the following?
File.join("")
File.join("", "")
File.join(nil)
File.join(nil, nil)
File.join(1,2)
File.join("/")
File.join("/", "/")

I'll give you a hint: none of these raise a TypeError. Ok, now here are the answers:
File.join("")       # ""    - ok
File.join("", "")   # "/"   - huh?
File.join(nil)      # ""    - expected a TypeError
File.join(nil, nil) # "/"   - wha..?  again, expected a TypeError
File.join(1,2)      # "1/2" - expected a TypeError
File.join("/")      # "/"   - hrm, ok, but...
File.join("/", "/") # "//"  - could be smarter

Calling .to_s on all the array arguments strikes me as inconsistent vis-a-vis File.dirname, File.basename, and File.extname, but I guess it's liveable.

Update: Portion of post about Ruby source code being confused was deleted. It turns out that the separator, for good or ill, is hard coded to '/'.

Read: Fun with File.join

Topic: Hoodwink'd, Day Two: Five Infiltrations Previous Topic   Next Topic Topic: Less Condescension, please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use