1. Ches Martin
  2. dotfiles

Source

dotfiles / .vim / UltiSnips / 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# TODO: move TM variable global functions to all.snippets?
global !p
def tm_filename(snip):
    snip.rv = snip.fn
    return snip
endglobal

global !p
def file_basename(snip):
    snip.rv = snip.basename
    return snip
endglobal

snippet rb "#!/usr/bin/env ruby -w" b
#!/usr/bin/env ruby${1: -${2:wKU}}

endsnippet

# shamelessly borrowed from the python snippets
# TODO: exclude after bracket chars too
snippet /(^|(?<=\W))\./ "self." r
self.
endsnippet

snippet elsif "elsif ___"
elsif ${1:condition}
	${2:# TODO}
endsnippet

snippet y ":yields: RDoc comment"
 :yields: ${0:arguments}
endsnippet

snippet # "Add '# =>' Marker"
# => 
endsnippet

snippet Array "Array.new(10) { |i| .. }  (Array)"
Array.new(${1:10}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:i}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet bm- "Benchmark_bmbm(__) do __ end"
TESTS = ${1:10_000}
Benchmark.bmbm do |results|
  $0
end
endsnippet

snippet Dir "Dir.glob('..') do |file| .. end  (Dir)"
Dir.glob(${1:"${2:dir/glob/*}"}) { |${3:file}| $0 }
endsnippet

snippet Dir "Dir['__']"
Dir[${1:"${2:glob/**/*.rb}"}]
endsnippet

snippet File "File.foreach ('..') do |line| .. end  (File)"
File.foreach(${1:"${2:path/to/file}"}) { |${3:line}| $0 }
endsnippet

snippet File "File_open('__') { |file| __ }"
File.open(${1:"${2:path/to/file}"}${3/(^[rwab+]+$)|.*/(?1:, ")/}${3:w}${3/(^[rwab+]+$)|.*/(?1:")/}) { |${4:file}| $0 }
endsnippet

snippet File "File_read('__')"
File.read(${1:"${2:path/to/file}"})
endsnippet

snippet Hash "Hash.new { |hash, key| hash[key] = .. }  (Hash)"
Hash.new { |${1:hash}, ${2:key}| $1[$2] = $3 }
endsnippet

snippet Md "Marshal.dump(obj, file)  (Md)"
File.open(${1:"${2:path/to/file}.dump"}, "wb") { |${3:file}| Marshal.dump(${4:obj}, $3) }
endsnippet

snippet Ml "Marshal.load(obj)  (Ml)"
File.open(${1:"${2:path/to/file}.dump"}, "rb") { |${3:file}| Marshal.load($3) }
endsnippet

snippet Pn- "PStore_new( __ )"
PStore.new(${1:"${2:file_name.pstore}"})
endsnippet

# TODO
snippet =b "RDoc documentation block"
`[[ $TM_LINE_INDEX != 0 ]] && echo; echo`=begin rdoc
	$0
=end
endsnippet

# TODO - intended to have a key shortcut trigger for wrapping text
snippet begin "Wrap in Begin … Rescue … End"
${TM_SELECTED_TEXT/([\t ]*).*/$1/m}begin
	${3:${TM_SELECTED_TEXT/(\A.*)|(.+)|\n\z/(?1:$0:(?2:\t$0))/g}}
${TM_SELECTED_TEXT/([\t ]*).*/$1/m}rescue ${1:Exception}${2/.+/ => /}${2:e}
${TM_SELECTED_TEXT/([\t ]*).*/$1/m}	$0
${TM_SELECTED_TEXT/([\t ]*).*/$1/m}end

endsnippet

snippet Yd- "YAML.dump(.., file)  (Yd-)"
File.open(${1:"${2:path/to/file}.yaml"}, "w") { |${3:file}| YAML.dump(${4:obj}, $3) }
endsnippet

snippet Yl- "YAML.load(file)  (Yl-)"
File.open(${1:"${2:path/to/file}.yaml"}) { |${3:file}| YAML.load($3) }
endsnippet

snippet end "__END__"
__END__

endsnippet

snippet am "alias_method ..  (am)"
alias_method :${1:new_name}, :${0:old_name}
endsnippet

snippet all "all? { |e| .. }  (all)" w
all? { |${1:e}| $0 }
endsnippet

snippet any "any? { |e| .. }  (any)" w
any? { |${1:e}| $0 }
endsnippet

snippet app "application { .. } (app)"
if __FILE__ == \$PROGRAM_NAME
	$0
end
endsnippet

# TODO
snippet as "assert(..)  (as)"
assert`snippet_paren.rb`${1:test}, "${0:Failure message.}"`snippet_paren.rb end`
endsnippet

snippet ase "assert_equal"
assert_equal`snippet_paren.rb`${1:expected}, ${0:actual}`snippet_paren.rb end`
endsnippet

snippet asid "assert_in_delta(..)  (asid)"
assert_in_delta`snippet_paren.rb`${1:expected_float}, ${2:actual_float}, ${0:2 ** -20}`snippet_paren.rb end`
endsnippet

snippet asio "assert_instance_of(..)  (asio)"
assert_instance_of`snippet_paren.rb`${1:ExpectedClass}, ${0:actual_instance}`snippet_paren.rb end`
endsnippet

snippet asko "assert_kind_of(..)  (asko)"
assert_kind_of`snippet_paren.rb`${1:ExpectedKind}, ${0:actual_instance}`snippet_paren.rb end`
endsnippet

snippet asm "assert_match(..)  (asm)"
assert_match`snippet_paren.rb`/${1:expected_pattern}/, ${0:actual_string}`snippet_paren.rb end`
endsnippet

snippet asn "assert_nil(..)  (asn)"
assert_nil`snippet_paren.rb`${0:instance}`snippet_paren.rb end`
endsnippet

snippet asnm "assert_no_match(..)  (asnm)"
assert_no_match`snippet_paren.rb`/${1:unexpected_pattern}/, ${0:actual_string}`snippet_paren.rb end`
endsnippet

snippet asne "assert_not_equal(..)  (asne)"
assert_not_equal`snippet_paren.rb`${1:unexpected}, ${0:actual}`snippet_paren.rb end`
endsnippet

snippet asnn "assert_not_nil(..)  (asnn)"
assert_not_nil`snippet_paren.rb`${0:instance}`snippet_paren.rb end`
endsnippet

snippet asns "assert_not_same(..)  (asns)"
assert_not_same`snippet_paren.rb`${1:unexpected}, ${0:actual}`snippet_paren.rb end`
endsnippet

snippet asnr "assert_nothing_raised(..) { .. }  (asnr)"
assert_nothing_raised(${1:Exception}) { $0 }
endsnippet

snippet asnt "assert_nothing_thrown { .. }  (asnt)"
assert_nothing_thrown { $0 }
endsnippet

snippet aso "assert_operator(..)  (aso)"
assert_operator`snippet_paren.rb`${1:left}, :${2:operator}, ${0:right}`snippet_paren.rb end`
endsnippet

snippet asr "assert_raise(..) { .. }  (asr)"
assert_raise(${1:Exception}) { $0 }
endsnippet

snippet asrt "assert_respond_to(..)  (asrt)"
assert_respond_to`snippet_paren.rb`${1:object}, :${0:method}`snippet_paren.rb end`
endsnippet

snippet ass "assert_same(..)  (ass)"
assert_same`snippet_paren.rb`${1:expected}, ${0:actual}`snippet_paren.rb end`
endsnippet

snippet ass "assert_send(..)  (ass)"
assert_send`snippet_paren.rb`[${1:object}, :${2:message}, ${0:args}]`snippet_paren.rb end`
endsnippet

snippet ast "assert_throws(..) { .. }  (ast)"
assert_throws(:${1:expected}) { $0 }
endsnippet

# TODO
# class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} < DelegateClass(${2:ParentClass})
#class ${1:`!p tm_filename(snip)`}${1/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} < DelegateClass(${2:ParentClass})
snippet cla- "class .. > DelegateClass .. initialize .. end  (class)"
class ${1:`!p file_basename(snip)`}${1/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} < DelegateClass(${2:ParentClass})
	def initialize${3/(^.*?\S.*)|.*/(?1:\()/}${3:args}${3/(^.*?\S.*)|.*/(?1:\))/}
		super(${4:del_obj})

		$0
	end


end
endsnippet

snippet cla "class .. < ParentClass .. initialize .. end"
class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} < ${2:ParentClass}
	def initialize${3/(^.*?\S.*)|.*/(?1:\()/}${3:args}${3/(^.*?\S.*)|.*/(?1:\))/}
		$0
	end


end
endsnippet

snippet cla "class .. < Struct .. initialize .. end"
${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} = Struct.new(:${2:attr_names}) do
	def ${3:method_name}
		$0
	end


end
endsnippet

snippet tc "class .. < Test::Unit::TestCase .. end  (tc)"
require 'test/unit'

require '${1:library_file_name}'

class Test${2:${1/([\w&&[^_]]+)|./\u$1/g}} < Test::Unit::TestCase
	def test_${3:case_name}
		$0
	end
end
endsnippet

snippet cla "class .. end  (cla)"
class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}}
	$0
end
endsnippet

snippet cla "class .. initialize .. end"
class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}}
	def initialize${2/(^.*?\S.*)|.*/(?1:\()/}${2:args}${2/(^.*?\S.*)|.*/(?1:\))/}
		$0
	end


end
endsnippet

snippet cla "class .. instance_methods .. undef .. initialize .. end  (class)"
class ${1:BlankSlate}
	instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ }

	def initialize${2/(^.*?\S.*)|.*/(?1:\()/}${2:args}${2/(^.*?\S.*)|.*/(?1:\))/}
		@${3:delegate} = ${4:delegate_object}

		$0
	end

	def method_missing(meth, *args, &block)
		@${3:delegate}.send(meth, *args, &block)
	end


end
endsnippet

snippet cla "class << self __ end"
class << ${1:self}
	$0
end
endsnippet

snippet clafn "class_from_name()  (clafn)"
split("::").inject(Object) { |par, const| par.const_get(const) }
endsnippet

snippet cl "classify { |e| .. }  (clas)"
classify { |${1:e}| $0 }
endsnippet

snippet col "collect { |e| .. }  (col)"
collect { |${1:e}| $0 }
endsnippet

snippet deec "deep_copy(..)  (dee)"
Marshal.load(Marshal.dump(${0:obj_to_copy}))
endsnippet

snippet defo "def(*args, opts={}) ... end"
def ${1:method_name}(${2:*args}${3:, opts=\{\}})
	$0
end
endsnippet

# FIXME: compliance test for UltiSnips transformations? :-)
snippet defm "define_method ... end"
define_method :${1:method_name} do${2/.+/ |/}${2:args}${2/.+/|/}
	$0
end
endsnippet

snippet defmm "def method_missing .. end  (mm)"
def method_missing(meth, *args, &blk)
	$0
end
endsnippet

snippet defs "def self .. end  (defs)"
def self.${1:class_method_name}
	$0
end
endsnippet

snippet deft "def test_ .. end  (deft)"
def test_${1:case_name}
	$0
end
endsnippet

snippet defd "def_delegator .. (defd)"
def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name}
endsnippet

snippet defds "def_delegators .. (defds)"
def_delegators :${1:@del_obj}, :${0:del_methods}
endsnippet

snippet deli "delete_if { |e| .. }  (deli)"
delete_if { |${1:e}| $0 }
endsnippet

snippet det "detect { |e| .. }  (det)"
detect { |${1:e}| $0 }
endsnippet

snippet dir "File.dirname(__FILE__)"
File.dirname(__FILE__)
endsnippet

# TODO
snippet do "do |obj| .. end (doo)" w
do${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1: |)/}${1:variable}${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}
	$0
end
endsnippet

snippet dow "downto(0) { |n| .. }  (dow)" w
downto(${1:0}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:n}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet ea "each { |e| .. }  (ea)" w
each { |${1:e}| $0 }
endsnippet

snippet eab "each_byte { |byte| .. }  (eab)" w
each_byte { |${1:byte}| $0 }
endsnippet

snippet eac- "each_char { |chr| .. }  (eac-)" w
each_char { |${1:chr}| $0 }
endsnippet

snippet eac- "each_cons(..) { |group| .. }  (eac-)" w
each_cons(${1:2}) { |${2:group}| $0 }
endsnippet

snippet eai "each_index { |i| .. }  (eai)" w
each_index { |${1:i}| $0 }
endsnippet

snippet eak "each_key { |key| .. }  (eak)" w
each_key { |${1:key}| $0 }
endsnippet

snippet eal "each_line { |line| .. }  (eal)" w
each_line$1 { |${2:line}| $0 }
endsnippet

snippet eap "each_pair { |name, val| .. }  (eap)" w
each_pair { |${1:name}, ${2:val}| $0 }
endsnippet

snippet eas- "each_slice { |group| .. }  (eas)" w
each_slice(${1:2}) { |${2:group}| $0 }
endsnippet

snippet eav "each_value { |val| .. }  (eav)" w
each_value { |${1:val}| $0 }
endsnippet

snippet eawi "each_with_index { |e, i| .. }  (eawi)" w
each_with_index { |${1:e}, ${2:i}| $0 }
endsnippet

snippet Forw- "extend Forwardable  (Forw-)"
extend Forwardable
endsnippet

# TODO
snippet fet "fetch(name) { |key| .. }  (fet)"
fetch(${1:name}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:key}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet fil "fill(range) { |i| .. }  (fil)"
fill(${1:range}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:i}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet fin "find { |e| .. }  (fin)"
find { |${1:e}| $0 }
endsnippet

snippet fina "find_all { |e| .. }  (fina)"
find_all { |${1:e}| $0 }
endsnippet

snippet flao "flatten_once  (fla)"
inject(Array.new) { |${1:arr}, ${2:a}| ${1:arr}.push(*${2:a}) }
endsnippet

snippet fl "flunk(..)  (fl)"
flunk`snippet_paren.rb`"${0:Failure message.}"`snippet_paren.rb end`
endsnippet

snippet gre "grep(;pattern;) { |match| .. }  (gre)"
grep(${1:/${2:pattern}/}) { |${3:match}| $0 }
endsnippet

snippet gsu "gsub(;..;) { |match| .. }  (gsu)"
gsub(/${1:pattern}/) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:match}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet : ":key => value (:)" i
:${1:key} => ${2:"${3:value}"}${4:, }
endsnippet

snippet Comp "include Comparable ..  (Comp)"
include Comparable

def <=>(other)
	$0
end
endsnippet

snippet Enum "include Enumerable ..  (Enum)"
include Enumerable

def each(&block)
	$0
end
endsnippet

snippet inj "inject(init) { |mem, var| .. }  (inj)"
inject${1/.+/(/}${1:init}${1/.+/)/} { |${2:mem}, ${3:var}| $0 }
endsnippet

snippet lam "lambda { |args| .. }  (lam)"
lambda { ${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${1:args}${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet loo "loop { __ }"
loop { $0 }
endsnippet

snippet mapwi- "map_with_index { |e, i| .. }  (mapwi)" w
enum_with_index.map { |${1:e}, ${2:i}| $0 }
endsnippet

snippet max "max { |a, b| .. }  (max)"
max { |a, b| $0 }
endsnippet

snippet min "min { |a, b| .. }  (min)"
min { |a, b| $0 }
endsnippet

snippet mod "module .. ClassMethods .. end"
module ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}}
	module ClassMethods
		$0
	end

	module InstanceMethods

	end

	def self.included(receiver)
		receiver.extend         ClassMethods
		receiver.send :include, InstanceMethods
	end
end
endsnippet

snippet mod "module .. end"
module ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}}
	$0
end
endsnippet

snippet mod "module .. module_function .. end"
module ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}}
	module_function

	$0
end
endsnippet

snippet nam "namespace :__ do __ end"
namespace :${1:${TM_FILENAME/\.\w+//}} do
	$0
end
endsnippet

snippet { "open yield block ({)"
{ ${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${1:variable}${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}${2:$TM_SELECTED_TEXT} 
endsnippet

snippet ope "open('path;or;url', 'w') do |doc| .. end (ope)"
open(${1:"${2:path/or/url/or/pipe}"}${3/(^[rwab+]+$)|.*/(?1:, ")/}${3:w}${3/(^[rwab+]+$)|.*/(?1:")/}) { |${4:io}| $0 }
endsnippet

snippet optp "option_parse { .. }  (optp)"
require 'optparse'

options = {${1::default => "args"}}

ARGV.options do |opts|
	opts.banner = "Usage:  #{File.basename(\$PROGRAM_NAME)} [OPTIONS]${2/^\s*$|(.*\S.*)/(?1: )/}${2:OTHER_ARGS}"

	opts.separator ""
	opts.separator "Specific Options:"

	$0

	opts.separator "Common Options:"

	opts.on( "-h", "--help",
	         "Show this message." ) do
		puts opts
		exit
	end

	begin
		opts.parse!
	rescue
		puts opts
		exit
	end
end

endsnippet

snippet par "partition { |e| .. }  (par)" w
partition { |${1:e}| $0 }
endsnippet

snippet patfh "path_from_here( __ )"
File.join(File.dirname(__FILE__), *%w[${1:rel path here}])
endsnippet

snippet ran "randomize  (ran)"
sort_by { rand }
endsnippet

snippet req "require '..'  (req)"
require '$0'
endsnippet

snippet ts "require 'tc_..' ..  (ts)"
require 'test/unit'

require 'tc_${1:test_case_file}'
require 'tc_${2:test_case_file}'

endsnippet

snippet reqg- "require_gem '__'"
require_gem '$0'
endsnippet

snippet rep "results_report(__) { __ }"
results.report("${1:name}:") { TESTS.times { $0 } }
endsnippet

snippet reve "reverse_each { |e| .. }  (rea)" w
reverse_each { |${1:e}| $0 }
endsnippet

snippet sca "scan(;..;) { |match| .. }  (sca)" w
scan(/${1:pattern}/) { |${2:match}| $0 }
endsnippet

snippet sinc "singleton_class()"
class << self; self end
endsnippet

snippet sor "sort { |a, b| .. }  (sor)" w
sort { |a, b| $0 }
endsnippet

snippet sorb "sort_by { |e| .. }  (sorb)" w
sort_by { |${1:e}| $0 }
endsnippet

snippet ste "step(2) { |e| .. }  (ste)" w
step(${1:2}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:n}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet sub "sub(;..;) { |match| .. }  (sub)" w
sub(/${1:pattern}/) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:match}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet tas "task :task_name =&gt; [:dependent, :tasks] do __ end"
desc "${1:Task description}"
task :${2:${3:task_name} => ${4:[:${5:dependent, :tasks}]}} do
	$0
end
endsnippet

snippet tim "times { |n| .. }  (tim)" w
times { ${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${1:n}${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet tra "transaction( __ ) do __ end"
transaction${1/(^.*?\S.*)|.*/(?1:\()/}${1:true}${1/(^.*?\S.*)|.*/(?1:\))/} { $0 }
endsnippet

snippet unif "unix_filter .. (uni)"
ARGF.each_line$1 do |${2:line}|
	$0
end
endsnippet

snippet unless "unless (unless)"
unless ${1:condition}
	$0
end
endsnippet

snippet until "until ___ end"
until ${1:condition}
	$0
end
endsnippet

snippet opt "opts.on(...)"
opts.on( "-${1:o}", "--${2:long-option-name}"${3/^\s*$|(.*\S.*)/(?1:, )/}${3:String},
         "${4:Option description.}" ) do |${6:opt}|
	$0
end
endsnippet

snippet upt "upto(1.0;0.0) { |n| .. }  (upt)"
upto(${1:1.0/0.0}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:n}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }
endsnippet

snippet usai "usage if()  (usai)"
if ARGV.$1
	abort "Usage:  #{\$PROGRAM_NAME} ${2:ARGS_GO_HERE}"
end
endsnippet

snippet usau "usage unless()  (usau)"
unless ARGV.$1
	abort "Usage:  #{\$PROGRAM_NAME} ${2:ARGS_GO_HERE}"
end
endsnippet

snippet when "when"
when ${1:condition}
	$0
endsnippet

snippet while "while ___ end"
while ${1:condition}
	$0
end
endsnippet

snippet xml- "xmlread(__)"
REXML::Document.new(File.read(${1:"${2:path/to/file}"}))
endsnippet

snippet xpa "xpath(__) { __ }"
elements.each(${1:"${2://XPath}"}) do |${3:node}|
	$0
end
endsnippet

snippet zip "zip(enums) { |row| .. }  (zip)" w
zip(${1:enums}) { |${2:row}| $0 }
endsnippet

###########################################################################
#                               EXTENSIONS                                #
###########################################################################

extends rails
#extends rspec