Skip to content

Instantly share code, notes, and snippets.

@tdegrunt
Created May 22, 2018 07:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tdegrunt/414ea735253031696a4b58b1f86fecf4 to your computer and use it in GitHub Desktop.
Save tdegrunt/414ea735253031696a4b58b1f86fecf4 to your computer and use it in GitHub Desktop.
Ruby programming with VS Code
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
# Used by dotenv library to load environment variables.
# .env
## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/
## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/
## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/
## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/
# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
/bin/
.test_queue_stats
# for vscode
/.vscode/
include:
- ./**/*.rb
exclude:
- spec/**/*
- test/**/*

Ruby programming with VS Code

  • OS
    • Windows 10
    • macOS Sierra

Prepare

  1. Install Ruby
  2. Install Gem packages globally
    • bundler
    • pry
    • byebug
    • for 'Ruby Solargraph' extension
      • solargraph (for code complete)
    • for 'rufo' extension
      • rufo (for formatting)
    • for 'Ruby' extension
      • ruby-debug-ide : 0.6.0 (for debug)
      • debase : 0.2.2.beta10 (for debug)
      • ruby-lint     (for lint)
      • reek (for lint)
      • rubocop (for lint)
      • fasterer (for lint)
      • debride (for lint)
      • rcodetools (for code complete)
        • Currently it does not work well with gem repository version, so you need to download it directly from github and replace it.
      • fastri (recommended on 'rcodetools' installing)

Install Texteditor

  1. Install VSCode
  2. Install Plugin
    • Simple Ruby ERB
    • rufo
    • Ruby Solargraph
    • or
    • Ruby (very heavy on windows)

Create Project

  1. Initialize

    $ # make project directory
    $ mkdir sampleproject
    $ cd sampleproject
    $ git init
    $ mkdir "lib"
    $
    $ # create solargraph config
    $ solargraph config .
    $ micro .solargraph.yml
    $
    $ # execute
    $ touch main.rb
    $ touch main.rb
    $ bundle exec ruby main.rb
    $
    $ # install requirement packages
    $ bundle init
    $ micro Gemfile
    $ bundle install --path vendor/bundle
    $ bundle install --binstubs            # create bundler command to ./bin/
    $
    $ # test
    $ bundle exec rspec --init
    $ mkdir spec/lib
    $ bundle exec rspec
    $
    $ 
    $ # if you use vscode-ruby, you can debug by debugger with VS Code integrated 
    $ # launch a debugger
    $ ## run debugger for launched
    $
    $ # attach to a debugger
    $ rdebug-ide main.rb
    $ ## and then, you run debugger for attaching
  2. Download files from Gist and deploy

Deployment

  • project root /
    • .bundle /
    • .vscode /
      • launch.json
      • tasks.json
    • bin /
    • lib /
      • bird.rb
    • spec /
      • lib /
        • bird_spec.rb
      • spec_helper.rb
    • vendor /
      • bundle /
    • .gitignore
    • .rspec
    • .solargraph.yml
    • main.rb
    • Gemfile
    • Guardfile
class Bird
# @return [String] Bird kind
attr_accessor :kind
# Initialize
# @param [String] kind Bird kind
# @return [Void]
def initialize(kind = 'chicken')
@kind = kind
end
# Tweet
# @return [String]
def tweet
if @kind == 'chicken'
'cock-a-doodle-doo'
elsif
'oink, oink'
end
end
end
require "spec_helper"
require "bird"
describe Bird do
it "says 'cock-a-doodle-doo'" do
bird = Bird.new('chicken')
expect(bird.tweet).to eq 'cock-a-doodle-doo'
end
end
source "https://rubygems.org"
group :development, :test do
gem 'rspec' # testing framework
# gem 'test-queue' # make rspec to parallel with no change to code
end
require './lib/bird'
bird = Bird.new('chicken')
puts bird.tweet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment