From: Simon Schuster Date: 2007-09-07T09:29:59+09:00 Subject: help me condence my code? I know this could be more idiomatic to ruby. it's basically to turn http://www.gutenberg.org/etext/18362 into an array. the "_no_extras" refers to me having snipped the intro and outro of the text outside of ruby. I still have to do something with the "SECTION" fields and the "A", "B", etc. fields. (not to mention some kind of linguistic parsing which would make f[rand(f.size)] + " " f[rand(f.size)] + " " .... link together in a coherent matter, but that's a little beyond me. any direction in this area would be kindly appreciated though! I'm thinking of separating it into different text files maybe. certain sections are almost whole sentences, they're grouped in all kinds of ways that will maybe help with this. no long-term goal, really, just learning ruby and having fun. :) anyhow, the sloppy newbie code is as follows: f = File.read("phrases_no_extra.txt") f = f.to_a f = f.each { |x| x.chop! } f.each_with_index { |x,y| # deletes the empty array items if x.size == 0 f.delete_at(y) end } f.each_with_index { |x,y| # deleting all but the last (which is spread of two lines) if x.include? "]" # of his comments f.delete_at(y) end } f.each_with_index { |x,y| # yes, this is me unable to recall how to do "or" hahaha. if x.include? "[" f.delete_at(y) end } f.delete_at(-1) # random whitespace item at the end from the last quote puts f[rand(f.size)]