Revised the Ruby snippets to conform to Rubocop rules.

This commit is contained in:
Eustaquio Rangel 2014-07-18 10:52:57 -03:00
parent 4cdf9dbf86
commit 8bb5faebbc

View File

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