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

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:

13 do |s|        = 'myawesomelibrary'
  s.version     = '0.0.0'        = '2017-01-01'
  s.summary     = "My awesome library summary"
  s.description = "My awesome library description"
  s.authors     = ["Awesome Programmer"]       = ''
  s.files       = ["lib/myawesomelibrary.rb"]
  s.homepage    =
  s.license       = 'MIT'

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.