From: Leo Date: 2004-10-06T04:39:54+09:00 Subject: Re: A ruby course Brian Schr�der wrote: > Hello Group, > > I need more help. > > Anybody has an idea for an exercise on extending existing classes. The code below introduce a new string concatenation operator '/' which concatenates two strings placing '/' beween them. This is useful when forming path from directory and filename components. class String def /(rhs) self.sub(%r{/+$}, '') + '/' + rhs.sub(%r{^/+}, '') end end if Now you can write the following code: $dir='/usr/local/bin' $name='ruby' $full_path= $dir/$name Also the '/' operator will make sure that the strings are joined by one and only one slash. Example: $dir='/badby/formed/dir///' $name='///foo' $dir/$name => '/badby/formed/dir/foo' Note, that poatterns like '///' were removed. Hope it helps, Leo -- [ LEOR _at_ WINLAB _dot_ RUTGERS _dot_ EDU ]