]> git.madduck.net Git - etc/vim.git/blob - .vim/snippets/ruby.snippets

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

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