Revised the Ruby snippets to conform to Rubocop rules.
This commit is contained in:
parent
4cdf9dbf86
commit
8bb5faebbc
@ -31,9 +31,9 @@ snippet beg
|
||||
end
|
||||
|
||||
snippet req require
|
||||
require "${1}"
|
||||
require '${1}'
|
||||
snippet reqr
|
||||
require_relative "${1}"
|
||||
require_relative '${1}'
|
||||
snippet #
|
||||
# =>
|
||||
snippet end
|
||||
@ -57,7 +57,7 @@ snippet deft
|
||||
snippet descendants
|
||||
class Class
|
||||
def descendants
|
||||
ObjectSpace.each_object(::Class).select {|klass| klass < self }
|
||||
ObjectSpace.each_object(::Class).select { |klass| klass < self }
|
||||
end
|
||||
end
|
||||
snippet if
|
||||
@ -228,13 +228,13 @@ snippet array
|
||||
snippet hash
|
||||
Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${0} }
|
||||
snippet file File.foreach() { |line| .. }
|
||||
File.foreach(${1:"path/to/file"}) { |${2:line}| ${0} }
|
||||
File.foreach(${1:'path/to/file'}) { |${2:line}| ${0} }
|
||||
snippet file File.read()
|
||||
File.read(${1:"path/to/file"})
|
||||
File.read(${1:'path/to/file'})
|
||||
snippet Dir Dir.global() { |file| .. }
|
||||
Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${0} }
|
||||
Dir.glob(${1:'dir/glob/*'}) { |${2:file}| ${0} }
|
||||
snippet Dir Dir[".."]
|
||||
Dir[${1:"glob/**/*.rb"}]
|
||||
Dir[${1:'glob/**/*.rb'}]
|
||||
snippet dir
|
||||
Filename.dirname(__FILE__)
|
||||
snippet deli
|
||||
@ -243,7 +243,7 @@ snippet fil
|
||||
fill(${1:range}) { |${2:i}| ${0} }
|
||||
# flatten_once()
|
||||
snippet flao
|
||||
inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}
|
||||
reduce(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2) }
|
||||
snippet zip
|
||||
zip(${1:enums}) { |${2:row}| ${0} }
|
||||
# downto(0) { |n| .. }
|
||||
@ -415,6 +415,10 @@ snippet seld
|
||||
end
|
||||
snippet lam
|
||||
lambda { |${1:args}| ${0} }
|
||||
snippet ->
|
||||
-> { ${0} }
|
||||
snippet ->a
|
||||
->(${1:args}) { ${0} }
|
||||
# I'm pretty sure that ruby users expect do to expand to do .. end
|
||||
snippet do
|
||||
do
|
||||
@ -428,12 +432,12 @@ snippet dov
|
||||
${2}
|
||||
end
|
||||
snippet :
|
||||
:${1:key} => ${2:"value"}
|
||||
${1:key}: ${2:'value'}
|
||||
snippet ope
|
||||
open(${1:"path/or/url/or/pipe"}, "${2:w}") { |${3:io}| ${0} }
|
||||
open('${1:path/or/url/or/pipe}', '${2:w}') { |${3:io}| ${0} }
|
||||
# path_from_here()
|
||||
snippet fpath
|
||||
File.join(File.dirname(__FILE__), *%2[${1:rel path here}])
|
||||
File.join(File.dirname(__FILE__), *['${1:rel path here}'])
|
||||
# unix_filter {}
|
||||
snippet unif
|
||||
ARGF.each_line${1} do |${2:line}|
|
||||
@ -441,21 +445,21 @@ snippet unif
|
||||
end
|
||||
# option_parse {}
|
||||
snippet optp
|
||||
require "optparse"
|
||||
require 'optparse'
|
||||
|
||||
options = {${0:default => "args"}}
|
||||
options = { ${0:default: 'args'} }
|
||||
|
||||
ARGV.options do |opts|
|
||||
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)}
|
||||
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)}"
|
||||
end
|
||||
snippet opt
|
||||
opts.on( "-${1:o}", "--${2:long-option-name}", ${3:String},
|
||||
"${4:Option description.}") do |${5:opt}|
|
||||
opts.on('-${1:o}', '--${2:long-option-name}', ${3:String}, '${4:Option description.}') do |${5:opt}|
|
||||
${0}
|
||||
end
|
||||
snippet tc
|
||||
require "test/unit"
|
||||
require 'test/unit'
|
||||
|
||||
require "${1:library_file_name}"
|
||||
require '${1:library_file_name}'
|
||||
|
||||
class Test${2:$1} < Test::Unit::TestCase
|
||||
def test_${3:case_name}
|
||||
@ -463,18 +467,18 @@ snippet tc
|
||||
end
|
||||
end
|
||||
snippet ts
|
||||
require "test/unit"
|
||||
require 'test/unit'
|
||||
|
||||
require "tc_${1:test_case_file}"
|
||||
require "tc_${2:test_case_file}"
|
||||
require 'tc_${1:test_case_file}'
|
||||
require 'tc_${2:test_case_file}'
|
||||
snippet as
|
||||
assert ${1:test}, "${2:Failure message.}"
|
||||
assert ${1:test}, '${2:Failure message.}'
|
||||
snippet ase
|
||||
assert_equal ${1:expected}, ${2:actual}
|
||||
snippet asne
|
||||
assert_not_equal ${1:unexpected}, ${2:actual}
|
||||
snippet asid
|
||||
assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2 ** -20}
|
||||
assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2**-20}
|
||||
snippet asi
|
||||
assert_includes ${1:collection}, ${2:object}
|
||||
snippet asio
|
||||
@ -486,9 +490,9 @@ snippet asn
|
||||
snippet asnn
|
||||
assert_not_nil ${1:instance}
|
||||
snippet asm
|
||||
assert_match /${1:expected_pattern}/, ${2:actual_string}
|
||||
assert_match(/${1:expected_pattern}/, ${2:actual_string})
|
||||
snippet asnm
|
||||
assert_no_match /${1:unexpected_pattern}/, ${2:actual_string}
|
||||
assert_no_match(/${1:unexpected_pattern}/, ${2:actual_string})
|
||||
snippet aso
|
||||
assert_operator ${1:left}, :${2:operator}, ${3:right}
|
||||
snippet asr
|
||||
@ -512,7 +516,7 @@ snippet ass assert_send(..)
|
||||
snippet asns
|
||||
assert_not_same ${1:unexpected}, ${2:actual}
|
||||
snippet ast
|
||||
assert_throws :${1:expected} { ${0} }
|
||||
assert_throws :${1:expected}, -> { ${0} }
|
||||
snippet astd
|
||||
assert_throws :${1:expected} do
|
||||
${0}
|
||||
@ -524,7 +528,7 @@ snippet asntd
|
||||
${0}
|
||||
end
|
||||
snippet fl
|
||||
flunk "${1:Failure message.}"
|
||||
flunk '${1:Failure message.}'
|
||||
# Benchmark.bmbm do .. end
|
||||
snippet bm-
|
||||
TESTS = ${1:10_000}
|
||||
@ -532,31 +536,31 @@ snippet bm-
|
||||
${0}
|
||||
end
|
||||
snippet rep
|
||||
results.report("${1:name}:") { TESTS.times { ${0} }}
|
||||
results.report('${1:name}:') { TESTS.times { ${0} } }
|
||||
# Marshal.dump(.., file)
|
||||
snippet Md
|
||||
File.open(${1:"path/to/file.dump"}, "wb") { |${2:file}| Marshal.dump(${3:obj}, $2) }
|
||||
File.open('${1:path/to/file.dump}', 'wb') { |${2:file}| Marshal.dump(${3:obj}, $2) }
|
||||
# Mashal.load(obj)
|
||||
snippet Ml
|
||||
File.open(${1:"path/to/file.dump"}, "rb") { |${2:file}| Marshal.load($2) }
|
||||
File.open('${1:path/to/file.dump}', 'rb') { |${2:file}| Marshal.load($2) }
|
||||
# deep_copy(..)
|
||||
snippet deec
|
||||
Marshal.load(Marshal.dump(${1:obj_to_copy}))
|
||||
snippet Pn-
|
||||
PStore.new(${1:"file_name.pstore"})
|
||||
PStore.new('${1:file_name.pstore}')
|
||||
snippet tra
|
||||
transaction(${1:true}) { ${0} }
|
||||
# xmlread(..)
|
||||
snippet xml-
|
||||
REXML::Document.new(File.read(${1:"path/to/file"}))
|
||||
REXML::Document.new(File.read('${1:path/to/file}'))
|
||||
# xpath(..) { .. }
|
||||
snippet xpa
|
||||
elements.each(${1:"//Xpath"}) do |${2:node}|
|
||||
elements.each('${1://Xpath}') do |${2:node}|
|
||||
${0}
|
||||
end
|
||||
# class_from_name()
|
||||
snippet clafn
|
||||
split("::").inject(Object) { |par, const| par.const_get(const) }
|
||||
split('::').inject(Object) { |par, const| par.const_get(const) }
|
||||
# singleton_class()
|
||||
snippet sinc
|
||||
class << self; self end
|
||||
@ -565,8 +569,8 @@ snippet nam
|
||||
${0}
|
||||
end
|
||||
snippet tas
|
||||
desc "${1:Task description}"
|
||||
task :${2:task_name => [:dependent, :tasks]} do
|
||||
desc '${1:Task description}'
|
||||
task ${2:task_name: [:dependent, :tasks]} do
|
||||
${0}
|
||||
end
|
||||
# block
|
||||
@ -574,7 +578,7 @@ snippet b
|
||||
{ |${1:var}| ${0} }
|
||||
snippet begin
|
||||
begin
|
||||
raise 'A test exception.'
|
||||
fail 'A test exception.'
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
puts e.backtrace.inspect
|
||||
@ -590,4 +594,4 @@ snippet debug
|
||||
snippet pry
|
||||
require 'pry'; binding.pry
|
||||
snippet strf
|
||||
strftime("${1:%Y-%m-%d %H:%M:%S %z}")${0}
|
||||
strftime('${1:%Y-%m-%d %H:%M:%S %z}')${0}
|
||||
|
Loading…
Reference in New Issue
Block a user