Skip to content

Instantly share code, notes, and snippets.

@nguyendangminh
Last active August 29, 2015 14:11
Show Gist options
  • Save nguyendangminh/fd3b2793c20f30d29512 to your computer and use it in GitHub Desktop.
Save nguyendangminh/fd3b2793c20f30d29512 to your computer and use it in GitHub Desktop.
Working with file in Ruby
# Reading whole file
bootstrap = File.read('config/bootstrap')
# Relative path.
# web_app/
# app.rb
# db/sample.db
# In the app.rb
"#{File.expand_path(File.dirname(__FILE__))}/db/sample.db"
# Directory listing
Dir[File.join(File.dirname(__FILE__), "../lib/collector/handlers/*.rb")].each do |file|
require File.join("collector/handlers", File.basename(file, File.extname(file)))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment