Help me condence my code?

Simon S. wrote:

I know this could be more idiomatic to ruby.

Don’t know about idiomatic, but here’s my
filter-split-filter take:

require ‘open-uri’

f = open(‘http://www.gutenberg.org/files/18362/18362.txt’).read.
gsub(/\s*[.*?]/m,‘’). # strip comments
split(“\r\n”). # DOS line endings
delete_if{ |e| e.empty? } # remove blank lines

puts f[ rand f.size ]

Regards,

my local copy has some extra (probably important) authorship/proj
gutenberg info at the beginning and end that I’ve stripped, but other
than that this code works perfectly. I really like how it’s split up
by lines per method. thanks a lot!

also is [ a literal bracket, or some kind of grouping device that
just happens to be also the boundary-character I’m looking for?

Simon S. wrote:

my local copy has some extra (probably important) authorship/proj
gutenberg info at the beginning and end that I’ve stripped, but other
than that this code works perfectly.

Yes, you could drop the open-uri stuff and just use your
File.read on your local copy, but I needed something to work
from…

I really like how it’s split up by lines per method. thanks a lot!

'welcome. It reflects the way I think about the problem.
Others may think differently. :slight_smile:

also is [ a literal bracket, or some kind of grouping device that
just happens to be also the boundary-character I’m looking for?

Literal bracket. Otherwise, it defines a range of characters.
E.g., [a-mA-M0-4] matches the first half of all alphanumerics.

Regards,