File.open('README', 'r') do |file|
file.inject { |contents, line| contents << line }
end
This will open up a file README and return the entire contents as a string. It's pretty cool, since I don't have to muck around with temporary variables much...and it's readable...well, if 'inject' makes sense to you. Also cool is that, like Java container classes, as long as you implement 'each' in your Ruby class, you get all the ones in Enumerable for free. You just have to include it.
Wilhem has built Annologger, a tool that lets people worship your dentist appointments.
No comments:
Post a Comment