About
Ruby Tips is a Website dedicated to Ruby programming language and Ruby on Rails web application framework. Here you will find all the latest news, tips and tricks on Ruby and Rails.
If you have any comments or suggestions about this site, please do let me know. One of the best places to get help on Ruby or Rails is the Ruby Forum (Sidebar on homepage contains a list of useful Ruby sites) . You can also contact me directly if you have any problems or questions on Ruby. I would try my best to answer them.
My contact address is j2contact@gmail.com.
My First Ruby Program
Following is my first serious program in Ruby. This searches for the given file name under a directory tree.
# This program will search for a filename in a given path
class FileSearch
attr_accessor :path, :pattern
def initialize (path, pattern)
@path = path
@pattern = pattern
end
def search(dirName=@path)
begin
dir = Dir.new(dirName)
rescue
return
end
dir.entries.each do
|entry|
puts entry if entry.upcase.match(@pattern)
absPath = dirName+"/"+entry
search(absPath) if (File.stat(absPath).directory? && !entry.match("^[.]"))
end
end
end
search = FileSearch.new("d:/ruby","RESUME")
search.search