I’m still learning Ruby so far and working on a small gem that allows you to do something as long as the current file your in includes a certain attribute (in my case ”). I took a look at some of the File class methods and never came across anything I was looking for. I do realize the popular Array method .include?, and I’m wondering if there’s a method for doing this in a bigger scale, which is applying it to the File class. Can anyone point out a File class method or script that does this?
Example:
# The Array class method scans the array for an item
arr = ['foo', 'bar', 'baz']
if arr.include?('foo')
# (insert text)
end
What I need to do:
if File.include?('')
# My code
end
Thanks!
Take a look:
Caution: this code reads entire file into memory. You better not apply it to huge files.
This is a more efficient way.