Ruby, etc

Learn all the things

He who enjoys doing and enjoys what he has done is happy. - Fortune Cookie

Setting Up a New Ruby or Rails Project

A checklist to follow when starting a new project if you are using rbenv or rvm:

Make sure this is in your .bashrc or .zshrc

1
alias be="bundle exec"

Then any time you would need bundle exec you can just use be. Or alternatively, Hal Fulton pointed out you can do bundle exec bash to get a bash shell that would be the same as using be each time :)

  1. Create a directory for your project and change into it.
  2. Create a Ruby version file: echo "2.4.0" > .ruby_version.
  3. Change out of directory and back in, and ensure your version of ruby is correct with ruby -v.
  4. Make sure Bundler is installed: gem install bundler.
  5. Create a Gemfile bundle init.
  6. Setup git repo with git init.
  7. Create a README file and put the name of your project and what it is used for.
  8. Add all files git add ..
  9. Commit git commit -m "inital commit".

Then if you are making a ruby gem:

  1. Use bundle gem myawesomegemor do it by hand (helps you to remember.. hehe)
  2. Create a gemspec touch myawesomelibrary.gemspec.
  3. Make directory: mkdir lib.
  4. Make library file: touch lib/myawesomelibrary.rb.
  5. Make test directory: mkdir test.
  6. Make test file: touch test/myawesomelibrary_test.rb.

Gem spec template:

1
2
3
4
5
6
7
8
9
10
11
12
13
Gem::Specification.new do |s|
  s.name        = 'myawesomelibrary'
  s.version     = '0.0.0'
  s.date        = '2017-01-01'
  s.summary     = "My awesome library summary"
  s.description = "My awesome library description"
  s.authors     = ["Awesome Programmer"]
  s.email       = 'myself@awesomeprogramming.com'
  s.files       = ["lib/myawesomelibrary.rb"]
  s.homepage    =
    'http://rubygems.org/gems/myawesomelibrary'
  s.license       = 'MIT'
end

If you are making a rails app:

Add the version of Rails you want to use to the Gemfile ie: rails "5.0.1" and bundle install. Then do rails new . to create a rails app with the same name as current directory.

Comments