]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/snippets/ruby.snippets
Update plug
[rbdr/dotfiles] / vim / snippets / ruby.snippets
... / ...
CommitLineData
1# #!/usr/bin/env ruby
2snippet #!
3 #!/usr/bin/env ruby
4
5# New Block
6snippet =b
7 =begin rdoc
8 ${1}
9 =end
10snippet y
11 :yields: ${1:arguments}
12snippet rb
13 #!/usr/bin/env ruby -wKU
14snippet beg
15 begin
16 ${3}
17 rescue ${1:Exception} => ${2:e}
18 end
19
20snippet req
21 require "${1}"${2}
22snippet #
23 # =>
24snippet end
25 __END__
26snippet case
27 case ${1:object}
28 when ${2:condition}
29 ${3}
30 end
31snippet when
32 when ${1:condition}
33 ${2}
34snippet def
35 def ${1:method_name}
36 ${2}
37 end
38snippet deft
39 def test_${1:case_name}
40 ${2}
41 end
42snippet if
43 if ${1:condition}
44 ${2}
45 end
46snippet ife
47 if ${1:condition}
48 ${2}
49 else
50 ${3}
51 end
52snippet elsif
53 elsif ${1:condition}
54 ${2}
55snippet unless
56 unless ${1:condition}
57 ${2}
58 end
59snippet while
60 while ${1:condition}
61 ${2}
62 end
63snippet for
64 for ${1:e} in ${2:c}
65 ${3}
66 end
67snippet until
68 until ${1:condition}
69 ${2}
70 end
71snippet cla class .. end
72 class ${1:`substitute(Filename(), '^.', '\u&', '')`}
73 ${2}
74 end
75snippet cla class .. initialize .. end
76 class ${1:`substitute(Filename(), '^.', '\u&', '')`}
77 def initialize(${2:args})
78 ${3}
79 end
80
81
82 end
83snippet cla class .. < ParentClass .. initialize .. end
84 class ${1:`substitute(Filename(), '^.', '\u&', '')`} < ${2:ParentClass}
85 def initialize(${3:args})
86 ${4}
87 end
88
89
90 end
91snippet cla ClassName = Struct .. do .. end
92 ${1:`substitute(Filename(), '^.', '\u&', '')`} = Struct.new(:${2:attr_names}) do
93 def ${3:method_name}
94 ${4}
95 end
96
97
98 end
99snippet cla class BlankSlate .. initialize .. end
100 class ${1:BlankSlate}
101 instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ }
102snippet cla class << self .. end
103 class << ${1:self}
104 ${2}
105 end
106# class .. < DelegateClass .. initialize .. end
107snippet cla-
108 class ${1:`substitute(Filename(), '^.', '\u&', '')`} < DelegateClass(${2:ParentClass})
109 def initialize(${3:args})
110 super(${4:del_obj})
111
112 ${5}
113 end
114
115
116 end
117snippet mod module .. end
118 module ${1:`substitute(Filename(), '^.', '\u&', '')`}
119 ${2}
120 end
121snippet mod module .. module_function .. end
122 module ${1:`substitute(Filename(), '^.', '\u&', '')`}
123 module_function
124
125 ${2}
126 end
127snippet mod module .. ClassMethods .. end
128 module ${1:`substitute(Filename(), '^.', '\u&', '')`}
129 module ClassMethods
130 ${2}
131 end
132
133 module InstanceMethods
134
135 end
136
137 def self.included(receiver)
138 receiver.extend ClassMethods
139 receiver.send :include, InstanceMethods
140 end
141 end
142# attr_reader
143snippet r
144 attr_reader :${1:attr_names}
145# attr_writer
146snippet w
147 attr_writer :${1:attr_names}
148# attr_accessor
149snippet rw
150 attr_accessor :${1:attr_names}
151# include Enumerable
152snippet Enum
153 include Enumerable
154
155 def each(&block)
156 ${1}
157 end
158# include Comparable
159snippet Comp
160 include Comparable
161
162 def <=>(other)
163 ${1}
164 end
165# extend Forwardable
166snippet Forw-
167 extend Forwardable
168# def self
169snippet defs
170 def self.${1:class_method_name}
171 ${2}
172 end
173# def method_missing
174snippet defmm
175 def method_missing(meth, *args, &blk)
176 ${1}
177 end
178snippet defd
179 def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name}
180snippet defds
181 def_delegators :${1:@del_obj}, :${2:del_methods}
182snippet am
183 alias_method :${1:new_name}, :${2:old_name}
184snippet app
185 if __FILE__ == $PROGRAM_NAME
186 ${1}
187 end
188# usage_if()
189snippet usai
190 if ARGV.${1}
191 abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3}
192 end
193# usage_unless()
194snippet usau
195 unless ARGV.${1}
196 abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3}
197 end
198snippet array
199 Array.new(${1:10}) { |${2:i}| ${3} }
200snippet hash
201 Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${3} }
202snippet file File.foreach() { |line| .. }
203 File.foreach(${1:"path/to/file"}) { |${2:line}| ${3} }
204snippet file File.read()
205 File.read(${1:"path/to/file"})${2}
206snippet Dir Dir.global() { |file| .. }
207 Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${3} }
208snippet Dir Dir[".."]
209 Dir[${1:"glob/**/*.rb"}]${2}
210snippet dir
211 Filename.dirname(__FILE__)
212snippet deli
213 delete_if { |${1:e}| ${2} }
214snippet fil
215 fill(${1:range}) { |${2:i}| ${3} }
216# flatten_once()
217snippet flao
218 inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}${3}
219snippet zip
220 zip(${1:enums}) { |${2:row}| ${3} }
221# downto(0) { |n| .. }
222snippet dow
223 downto(${1:0}) { |${2:n}| ${3} }
224snippet ste
225 step(${1:2}) { |${2:n}| ${3} }
226snippet tim
227 times { |${1:n}| ${2} }
228snippet upt
229 upto(${1:1.0/0.0}) { |${2:n}| ${3} }
230snippet loo
231 loop { ${1} }
232snippet ea
233 each { |${1:e}| ${2} }
234snippet ead
235 each do |${1:e}|
236 ${2}
237 end
238snippet eab
239 each_byte { |${1:byte}| ${2} }
240snippet eac- each_char { |chr| .. }
241 each_char { |${1:chr}| ${2} }
242snippet eac- each_cons(..) { |group| .. }
243 each_cons(${1:2}) { |${2:group}| ${3} }
244snippet eai
245 each_index { |${1:i}| ${2} }
246snippet eaid
247 each_index do |${1:i}|
248 end
249snippet eak
250 each_key { |${1:key}| ${2} }
251snippet eakd
252 each_key do |${1:key}|
253 ${2}
254 end
255snippet eal
256 each_line { |${1:line}| ${2} }
257snippet eald
258 each_line do |${1:line}|
259 ${2}
260 end
261snippet eap
262 each_pair { |${1:name}, ${2:val}| ${3} }
263snippet eapd
264 each_pair do |${1:name}, ${2:val}|
265 ${3}
266 end
267snippet eas-
268 each_slice(${1:2}) { |${2:group}| ${3} }
269snippet easd-
270 each_slice(${1:2}) do |${2:group}|
271 ${3}
272 end
273snippet eav
274 each_value { |${1:val}| ${2} }
275snippet eavd
276 each_value do |${1:val}|
277 ${2}
278 end
279snippet eawi
280 each_with_index { |${1:e}, ${2:i}| ${3} }
281snippet eawid
282 each_with_index do |${1:e},${2:i}|
283 ${3}
284 end
285snippet reve
286 reverse_each { |${1:e}| ${2} }
287snippet reved
288 reverse_each do |${1:e}|
289 ${2}
290 end
291snippet inj
292 inject(${1:init}) { |${2:mem}, ${3:var}| ${4} }
293snippet injd
294 inject(${1:init}) do |${2:mem}, ${3:var}|
295 ${4}
296 end
297snippet map
298 map { |${1:e}| ${2} }
299snippet mapd
300 map do |${1:e}|
301 ${2}
302 end
303snippet mapwi-
304 enum_with_index.map { |${1:e}, ${2:i}| ${3} }
305snippet sor
306 sort { |a, b| ${1} }
307snippet sorb
308 sort_by { |${1:e}| ${2} }
309snippet ran
310 sort_by { rand }
311snippet all
312 all? { |${1:e}| ${2} }
313snippet any
314 any? { |${1:e}| ${2} }
315snippet cl
316 classify { |${1:e}| ${2} }
317snippet col
318 collect { |${1:e}| ${2} }
319snippet cold
320 collect do |${1:e}|
321 ${2}
322 end
323snippet det
324 detect { |${1:e}| ${2} }
325snippet detd
326 detect do |${1:e}|
327 ${2}
328 end
329snippet fet
330 fetch(${1:name}) { |${2:key}| ${3} }
331snippet fin
332 find { |${1:e}| ${2} }
333snippet find
334 find do |${1:e}|
335 ${2}
336 end
337snippet fina
338 find_all { |${1:e}| ${2} }
339snippet finad
340 find_all do |${1:e}|
341 ${2}
342 end
343snippet gre
344 grep(${1:/pattern/}) { |${2:match}| ${3} }
345snippet sub
346 ${1:g}sub(${2:/pattern/}) { |${3:match}| ${4} }
347snippet sca
348 scan(${1:/pattern/}) { |${2:match}| ${3} }
349snippet scad
350 scan(${1:/pattern/}) do |${2:match}|
351 ${3}
352 end
353snippet max
354 max { |a, b| ${1} }
355snippet min
356 min { |a, b| ${1} }
357snippet par
358 partition { |${1:e}| ${2} }
359snippet pard
360 partition do |${1:e}|
361 ${2}
362 end
363snippet rej
364 reject { |${1:e}| ${2} }
365snippet rejd
366 reject do |${1:e}|
367 ${2}
368 end
369snippet sel
370 select { |${1:e}| ${2} }
371snippet seld
372 select do |${1:e}|
373 ${2}
374 end
375snippet lam
376 lambda { |${1:args}| ${2} }
377snippet do
378 do |${1:variable}|
379 ${2}
380 end
381snippet :
382 :${1:key} => ${2:"value"}${3}
383snippet ope
384 open(${1:"path/or/url/or/pipe"}, "${2:w}") { |${3:io}| ${4} }
385# path_from_here()
386snippet patfh
387 File.join(File.dirname(__FILE__), *%2[${1:rel path here}])${2}
388# unix_filter {}
389snippet unif
390 ARGF.each_line${1} do |${2:line}|
391 ${3}
392 end
393# option_parse {}
394snippet optp
395 require "optparse"
396
397 options = {${1:default => "args"}}
398
399 ARGV.options do |opts|
400 opts.banner = "Usage: #{File.basename($PROGRAM_NAME)}
401snippet opt
402 opts.on( "-${1:o}", "--${2:long-option-name}", ${3:String},
403 "${4:Option description.}") do |${5:opt}|
404 ${6}
405 end
406snippet tc
407 require "test/unit"
408
409 require "${1:library_file_name}"
410
411 class Test${2:$1} < Test::Unit::TestCase
412 def test_${3:case_name}
413 ${4}
414 end
415 end
416snippet ts
417 require "test/unit"
418
419 require "tc_${1:test_case_file}"
420 require "tc_${2:test_case_file}"${3}
421snippet as
422 assert(${1:test}, "${2:Failure message.}")${3}
423snippet ase
424 assert_equal(${1:expected}, ${2:actual})${3}
425snippet asne
426 assert_not_equal(${1:unexpected}, ${2:actual})${3}
427snippet asid
428 assert_in_delta(${1:expected_float}, ${2:actual_float}, ${3:2 ** -20})${4}
429snippet asio
430 assert_instance_of(${1:ExpectedClass}, ${2:actual_instance})${3}
431snippet asko
432 assert_kind_of(${1:ExpectedKind}, ${2:actual_instance})${3}
433snippet asn
434 assert_nil(${1:instance})${2}
435snippet asnn
436 assert_not_nil(${1:instance})${2}
437snippet asm
438 assert_match(/${1:expected_pattern}/, ${2:actual_string})${3}
439snippet asnm
440 assert_no_match(/${1:unexpected_pattern}/, ${2:actual_string})${3}
441snippet aso
442 assert_operator(${1:left}, :${2:operator}, ${3:right})${4}
443snippet asr
444 assert_raise(${1:Exception}) { ${2} }
445snippet asnr
446 assert_nothing_raised(${1:Exception}) { ${2} }
447snippet asrt
448 assert_respond_to(${1:object}, :${2:method})${3}
449snippet ass assert_same(..)
450 assert_same(${1:expected}, ${2:actual})${3}
451snippet ass assert_send(..)
452 assert_send([${1:object}, :${2:message}, ${3:args}])${4}
453snippet asns
454 assert_not_same(${1:unexpected}, ${2:actual})${3}
455snippet ast
456 assert_throws(:${1:expected}) { ${2} }
457snippet asnt
458 assert_nothing_thrown { ${1} }
459snippet fl
460 flunk("${1:Failure message.}")${2}
461# Benchmark.bmbm do .. end
462snippet bm-
463 TESTS = ${1:10_000}
464 Benchmark.bmbm do |results|
465 ${2}
466 end
467snippet rep
468 results.report("${1:name}:") { TESTS.times { ${2} }}
469# Marshal.dump(.., file)
470snippet Md
471 File.open(${1:"path/to/file.dump"}, "wb") { |${2:file}| Marshal.dump(${3:obj}, $2) }${4}
472# Mashal.load(obj)
473snippet Ml
474 File.open(${1:"path/to/file.dump"}, "rb") { |${2:file}| Marshal.load($2) }${3}
475# deep_copy(..)
476snippet deec
477 Marshal.load(Marshal.dump(${1:obj_to_copy}))${2}
478snippet Pn-
479 PStore.new(${1:"file_name.pstore"})${2}
480snippet tra
481 transaction(${1:true}) { ${2} }
482# xmlread(..)
483snippet xml-
484 REXML::Document.new(File.read(${1:"path/to/file"}))${2}
485# xpath(..) { .. }
486snippet xpa
487 elements.each(${1:"//Xpath"}) do |${2:node}|
488 ${3}
489 end
490# class_from_name()
491snippet clafn
492 split("::").inject(Object) { |par, const| par.const_get(const) }
493# singleton_class()
494snippet sinc
495 class << self; self end
496snippet nam
497 namespace :${1:`Filename()`} do
498 ${2}
499 end
500snippet tas
501 desc "${1:Task description\}"
502 task :${2:task_name => [:dependent, :tasks]} do
503 ${3}
504 end