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