Recently, I watched some Ruby on Rails live-stream and I found out that there is nice feature in VSCode that I didn’t know.

It’s possible to build custom code snippets and use them with only a few keystrokes. This is great productivity improvement.

I added two snippets for Rspec code skeleton and simple Ruby class with two predefined methods, like this:

Code -> Preferences -> User Snippets -> ruby.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
"Rspec template": {
"prefix": "desc",
"body": [
"require 'rails_helper'",
"",
"describe MyClass do",
" subject { described_class.new(params) }",
" let(:params) {{",
"",
" }}",
"",
" context '' do",
" it '' do",
"",
" end",
" end",
"end"
],
"description": "Generates RSpec inital skeleton"
},
"Class template": {
"prefix": "cls",
"body": [
"# frozen_string_literal: true",
"",
"class MyClass",
"",
" def initialize()",
"",
" end",
"",
" def self.call()",
"",
" end",
"end"
],
"description": "Generates new Class template"
},
}

Link to docs: https://code.visualstudio.com/docs/editor/userdefinedsnippets