From: "Ara.T.Howard" Date: 2004-05-21T00:13:47+09:00 Subject: Re: Files ugly clone On Thu, 20 May 2004, Simon Strandgaard wrote: > I want to clone a filedescriptor, but no matter > what I try I becomes ugly. The nice solution doesn't > seems to work. > > f1 = File.open(__FILE__, 'r') > f1.seek(5) > p f1.pos # -> 5 > f2 = f1.clone.reopen(f1) # this is nasty.. but works > f2.seek(10) > p f2.pos # -> 10 > # check harmless > p f1.pos # -> 5 > > how can I make a nice clone? doesn't this do it? ~ > cat a.rb f1 = File.open(__FILE__, 'r') f1.seek(5) p f1.pos # -> 5 #f2 = f1.clone.reopen(f1) # this is nasty.. but works f2 = f1.dup f2.seek(10) p f2.pos # -> 10 # check harmless p f1.pos # -> 5 ~ > ruby a.rb 5 10 5 -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | "640K ought to be enough for anybody." - Bill Gates, 1981 ===============================================================================