From: daz Date: 2003-05-26T11:17:29+09:00 Subject: Re: Getting '\' to be used as the separator in Dir.getwd -- how to? "Richard" wrote: > > I had used: > > sCurDir = Dir.getwd.gsub(/\//, '\\') > > 1. Am I correct in assuming File::ALT_SEPARATOR ought to be set by the > group that ports Ruby to a platform? > As a 1st-year Rubyist, I yield to the hackers. At present, platforms that are not DOS-like have ALT_SEPARATOR set to nil so my solution wasn't portable. separator = rb_obj_freeze(rb_str_new2("/")); rb_define_const(rb_cFile, "SEPARATOR", separator); #ifdef DOSISH rb_define_const(rb_cFile, "ALT_SEPARATOR", rb_obj_freeze(rb_str_new2("\\"))); #else rb_define_const(rb_cFile, "ALT_SEPARATOR", Qnil); #endif > 2. Am I also correct that the "!" operator is not significant because > you have to have a target variable to receive the transformed w.d. > string? > As I understand things; Dir.getwd returns the w.d. as a value, say, aString1. aString1.gsub!(...) returns aString1 (modified in place) whereas aString1.gsub(...) would return aString2, leaving aString1 as unreferenced garbage. Only one string emerges as the value of the expression, whether you explicitly assign it or use, for example, next_ruby_method(Dir.getwd) -or- puts Dir.getwd.gsub(...) --- To be portable, you need something like - wd = Dir.getwd.gsub!(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) -or- wd = Dir.getwd wd.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR -or your - sCurDir = Dir.getwd.gsub(/\//, '\\') which IMHO looks portable using non-! gsub (and not as ugly). daz