From: Axel Etzold Date: 2008-06-11T01:20:29+09:00 Subject: Re: Making separate File -------- Original-Nachricht -------- > Datum: Wed, 11 Jun 2008 01:11:42 +0900 > Von: Michel Son > An: ruby-talk@ruby-lang.org > Betreff: Re: Making separate File > Robert Klemme wrote: > > 2008/6/10 Michel Son : > >> second file for second class "class2.rb" > >> and so on... > >> > >> I would be very thankful to you dear > > > > For what exactly? I mean, opening two files in an editor and copy + > > pasting the code there can't be that hard, can it? > > > > Cheers > > > > robert > > > Without opening them. It should seprate the code based on "class" > keyword and storing it in other file using ruby code. > -- > Posted via http://www.ruby-forum.com/. Michel, supposing that the original code is in "sourcefile", and that there is no text in between the classes, you can use something like this: text=IO.readlines(sourcefile) classes=text.split(/(?=class )/).delete_if{|text| /^class/.match(text)==nil} classes.each_with_index{|c_text,i| f=File.new("class_file_" + i.to_s + '.rb',"w") f.puts c_text f.close } Best regards, Axel -- GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen! Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx