-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby.snippets
329 lines (266 loc) · 4.87 KB
/
ruby.snippets
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
snippet #! "hash bang"
#!/usr/bin/ruby
endsnippet
snippet =b "begin rdoc"
=begin rdoc
${1}
=end
endsnippet
snippet require "require"
require '${1}'${2}
endsnippet
snippet case "case"
case ${1:object}
when ${2:condition}
${3}
end
endsnippet
snippet when "when"
when ${1:condition}
${2}
endsnippet
snippet def "method def"
def ${1:method_name}
${2}
end
endsnippet
snippet init "initialize"
def initialize
${1:#my method}
end
endsnippet
snippet if "if"
if ${1:condition}
${2}
end
endsnippet
snippet ife "if-else"
if ${1:condition}
${2}
else
${3}
end
endsnippet
snippet elsif "elsif"
elsif ${1:condition}
${2}
endsnippet
snippet unless "unless"
unless ${1:condition}
${2}
end
endsnippet
snippet while "while"
while ${1:condition}
${2}
end
endsnippet
snippet until "until"
until ${1:condition}
${2}
end
endsnippet
snippet class "class"
class ${1:ClassName}
$0
end
endsnippet
snippet cla "class with def"
class ${1:ClassName}
def initialize${2: param1}
${3:#methods}
end$0
end
endsnippet
snippet mod "module"
module ${1:`substitute(Filename(), '^.', '\u&', '')`}
${2}
end
endsnippet
snippet attr "attribute writter"
attr_writter :${1:attr_names}
endsnippet
snippet attr "attribute reader"
attr_reader :${1:attr_names}
endsnippet
snippet attr "attribute accesor"
attr_accesor :${1:attr_names}
endsnippet
snippet attr_r "attr_reader"
attr_reader :${1:attr_names}
endsnippet
snippet attr_w "attr_writter"
attr_writer :${1:attr_names}
endsnippet
snippet attr_a "attr_accesor"
attr_accessor :${1:attr_names}
endsnippet
snippet Enum "enum def"
include Enumerable
def each(&block)
${1}
end
endsnippet
snippet Comp "include comparable"
include Comparable
def <=>(other)
${1}
end
endsnippet
snippet defs "define class method"
def self.${1:class_method_name}
${2}
end
endsnippet
snippet defmm "define method missing"
def method_missing(meth, *args, &blk)
${1}
end
endsnippet
snippet defd "method delegator"
def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name}
endsnippet
snippet defds "method delegators"
def_delegators :${1:@del_obj}, :${2:del_methods}
endsnippet
snippet am "alias method"
alias_method :${1:new_name}, :${2:old_name}
endsnippet
snippet app "app"
if __FILE__ == $PROGRAM_NAME
${1}
end
endsnippet
snippet file "file read"
File.read(${1:"path/to/file"})${2}
endsnippet
snippet Dir "Dirglobal"
Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${3} }
endsnippet
snippet Dir "Dir[..]"
Dir[${1:"glob/**/*.rb"}]${2}
endsnippet
snippet dir "filename dir"
Filename.dirname(__FILE__)
endsnippet
snippet downto "downto" w
downto(${1:0}) { |${2:n}| ${3} }
endsnippet
snippet step "step" w
step(${1:2}) { |${2:n}| ${3} }
endsnippet
snippet times "times" w
times { |${1:n}| ${2} }
endsnippet
snippet upto "upto" w
upto(${1:1.0/0.0}) { |${2:n}| ${3} }
endsnippet
snippet each "each" w
each { |${1:e}| ${2} }
endsnippet
snippet inject "inject" w
inject(${1:init}) { |${2:mem}, ${3:var}| ${4} }
endsnippet
snippet map "map" w
map { |${1:e}| ${2} }
endsnippet
snippet sub "substitute" w
${1:g}sub(${2:/pattern/}) { |${3:match}| ${4} }
endsnippet
snippet scan "scan" w
scan(${1:/pattern/}) { |${2:match}| ${3} }
endsnippet
snippet max "max" w
max { |a, b|, ${1} }
endsnippet
snippet min "min" w
min { |a, b|, ${1} }
endsnippet
snippet lambda "lambda" w
lambda { |${1:args}| ${2} }
endsnippet
snippet do "do" w
do |${1:variable}|
${2}
end
endsnippet
snippet testclass "test class"
require "test/unit"
require "${1:library_file_name}"
class Test${2:$1} < Test::Unit::TestCase
def test_${3:case_name}
${4}
end
end
endsnippet
snippet testclass "rails unit test class" b
require 'test_helper'
class ${1:ClassName}Test < ActiveSupport::TestCase
test "${2:test name}" do
assert ${3:"the truth"}
end
end
endsnippet
snippet as "assert"
assert(${1:test}, "${2:Failure message.}")${3}
endsnippet
snippet ase "assert equal"
assert_equal(${1:expected}, ${2:actual})${3}
endsnippet
snippet logger "special logger"
logger.info "\n---------------"
logger.info $0
logger.info '---------------'
endsnippet
snippet puts "special puts"
puts "\n-------------"
puts $0
puts '--------------'
endsnippet
snippet i18 "I18n.translation" w
I18n.t("${1}")${2}
endsnippet
snippet find "capybara find"
find('${1}')${2}
endsnippet
snippet find "AR find"
find(${1})${2}
endsnippet
snippet f.c "factory.create" w
Factory.create( ${1} )
endsnippet
snippet controller "rails controller"
class ${1:ClassName} < ApplicationController
def index
${2}
end
end
endsnippet
snippet model "rails model"
class ${1:ModelName} < ActiveRecord::Base
${2}
end
endsnippet
snippet namespace "namespace"
namespace :${1:my_namespace} do
$0
end
endsnippet
snippet desc "describe" b
describe "${1}" do
it "${2}" do
${3}
end
end
endsnippet
snippet it "it" b
it '${2}' do
${3}
end
endsnippet
snippet f.b "factory build" w
Factory.build( :${1} )
endsnippet
snippet # "var interpolation" i
#{${1}}${2}
endsnippet