From: Pavel Varela Date: 2010-10-09T01:18:00+09:00 Subject: Re: each_with_index > The Article object should have a title and a text. > A way to get a title is : > > choice = gets.to_i - 1 # the array starts at 0 > article = @array_of_splits[choice] # returns the Article, show the > fields you want > title = article.title > > In the similar way, a text can be acquired. But we don't know a name > of an Article object's method to obtain a text. > You should know the name of the method. > > Regards, thanks, i made it up this way: def show_titles file = File.read("articles_file.txt") raw_articles = file.split("\n\n") raw_articles.each do |elem| title, *text = elem.split("\n") @array_of_splits << Article.new(title, text.join("\n")) # w\o the whole text in one line end @array_of_splits.each_with_index do |elem, index| puts "#{index}: #{elem.title}" end puts puts "Pick the article u wanna see by entering the number of the title" choice = gets.to_i puts puts "Title: #{@array_of_splits[choice].title}" puts "Text: #{@array_of_splits[choice].text}" end -- Posted via http://www.ruby-forum.com/.