From: Dave Howell Date: 2010-10-06T17:06:41+09:00 Subject: Re: The Third Ruby - Ever Comes Out at Night? On Oct 2, 2010, at 2:01 , Mike Stephens wrote: > Often you see that Ruby can be object-oriented, functional or > procedural. > > What would you expect to see in a program that made you say "Ah this is > procedural Ruby!"? Fewer classes, and heavy use of variables. mydata = File.open('myfile.txt').readlines funparts = Array.new loop mydata.size do |idx| funparts << mydata[idx][/regex-that-matches-fun-parts/,1] end for funpart in funparts puts funpart end This code assumes that the data is 'dead.' It's just sitting there, waiting for me to act upon it. I've really had to pay attention to my coding. I keep reminding myself that Ruby will flow much better if I don't think of data as something I have to manipulate myself, but rather as entities whom are expecting me to tell them to manipulate themselves. "Don't make me search through you looking for the fun parts! You should do that work yourself, and just tell me what you come up with!" puts (funparts = File.open('myfile.txt').readlines.collect do |line| line[/regex-that-matches-fun-parts/,1] end.compact).join("\n") Instead of walking myself through the file contents line by line, picking out the good bits, I told the array to do it's own flippin' walking. At least that's what I think procedure-oriented Ruby would look like.