priority -50 # # Global functions # global !p def write_instance_vars(arglist, snip): args = str(arglist).split(',') for arg in args: name = arg.strip().replace(':', ' ').split(' ', 1)[0] if name: snip += ' @{} = {}'.format(name, name) else: snip += '' endglobal # # Snippets # snippet #! "#!/usr/bin/env ruby" b #!/usr/bin/env ruby $0 endsnippet snippet "^# ?[uU][tT][fF]-?8" "# encoding: UTF-8" r # encoding: UTF-8 $0 endsnippet snippet "\b(de)?f" "def ..." r def ${1:function_name}${2:(${3:*args})} $0 end endsnippet snippet defi "def initialize ..." def initialize($1)`!p write_instance_vars(t[1],snip)`$0 end endsnippet snippet defr "def ... rescue ..." def ${1:function_name}${2:(${3:*args})} $4 rescue $0 end endsnippet snippet For "(..).each { || }" (${1:from}..${2:to}).each { |${3:i}| $0 } endsnippet snippet "(\S+)\.Merge!" ".merge!() { |,,| }" r `!p snip.rv=match.group(1)`.merge!(${1:other_hash}) { |${2:key},${3:oldval},${4:newval}| ${5:block} } endsnippet snippet "(\S+)\.merge!" ".merge!() do |,,| end" r `!p snip.rv=match.group(1)`.merge!(${1:other_hash}) do |${2:key},${3:oldval},${4:newval}| ${0:block} end endsnippet snippet "(\S+)\.Del(ete)?_?if" ".delete_if { |,| }" r `!p snip.rv=match.group(1)`.delete_if { |${1:key},${2:value}| $0 } endsnippet snippet "(\S+)\.del(ete)?_?if" ".delete_if do |,| end" r `!p snip.rv=match.group(1)`.delete_if do |${1:key},${2:value}| $0 end endsnippet snippet "(\S+)\.Keep_?if" ".keep_if { |,| }" r `!p snip.rv=match.group(1)`.keep_if { |${1:key},${2:value}| $0 } endsnippet snippet "(\S+)\.keep_?if" ".keep_if do ,| end" r `!p snip.rv=match.group(1)`.keep_if do |${1:key},${2:value}| $0 end endsnippet snippet "(\S+)\.Reject" ".reject { |,| }" r `!p snip.rv=match.group(1)`.reject { |${1:key},${2:value}| $0 } endsnippet snippet "(\S+)\.reject" ".reject do ,| end" r `!p snip.rv=match.group(1)`.reject do |${1:key},${2:value}| $0 end endsnippet snippet "(\S+)\.Select" ".select { || }" r `!p snip.rv=match.group(1)`.select { |${1:item}| ${2:block} } endsnippet snippet "(\S+)\.select" ".select do || end" r `!p snip.rv=match.group(1)`.select do |${1:item}| ${0:block} end endsnippet snippet "(\S+)\.Sort" ".sort { |,| }" r `!p snip.rv=match.group(1)`.sort { |${1:a},${2:b}| $0 } endsnippet snippet "(\S+)\.sort" ".sort do |,| end" r `!p snip.rv=match.group(1)`.sort do |${1:a},${2:b}| $0 end endsnippet snippet "(\S+)\.Each_?k(ey)?" ".each_key { || }" r `!p snip.rv=match.group(1)`.each_key { |${1:key}| $0 } endsnippet snippet "(\S+)\.each_?k(ey)?" ".each_key do |key| end" r `!p snip.rv=match.group(1)`.each_key do |${1:key}| $0 end endsnippet snippet "(\S+)\.Each_?val(ue)?" ".each_value { || }" r `!p snip.rv=match.group(1)`.each_value { |${1:value}| $0 } endsnippet snippet "(\S+)\.each_?val(ue)?" ".each_value do || end" r `!p snip.rv=match.group(1)`.each_value do |${1:value}| $0 end endsnippet snippet "(\S+)\.ea" ".each do || end" r `!p snip.rv=match.group(1)`.each { |${1:e}| $0 } endsnippet snippet "(\S+)\.ead" ".each do || end" r `!p snip.rv=match.group(1)`.each do |${1:e}| $0 end endsnippet snippet "each_?s(lice)?" ".each_slice(n) do |slice| end" r ${1:elements}.each_slice(${2:2}) do |${3:slice}| $0 end endsnippet snippet "Each_?s(lice)?" ".each_slice(n) { |slice| }" r ${1:elements}.each_slice(${2:2}) { |${3:slice}| $0 } endsnippet snippet "(\S+)\.Map" ".map { || }" r `!p snip.rv=match.group(1)`.map { |${1:`!p element_name = match.group(1).lstrip('$@') ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) try: wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) snip.rv = wmatch.group(1).lower() except: snip.rv = 'element' `}| $0 } endsnippet snippet "(\S+)\.map" ".map do || end" r `!p snip.rv=match.group(1)`.map do |${1:`!p element_name = match.group(1).lstrip('$@') ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) try: wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) snip.rv = wmatch.group(1).lower() except: snip.rv = 'element' `}| $0 end endsnippet snippet "(\S+)\.Rev(erse)?_?each" ".reverse_each { || }" r `!p snip.rv=match.group(1)`.reverse_each { |${1:`!p element_name = match.group(1).lstrip('$@') ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) try: wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) snip.rv = wmatch.group(1).lower() except: snip.rv = 'element' `}| $0 } endsnippet snippet "(\S+)\.rev(erse)?_?each" ".reverse_each do || end" r `!p snip.rv=match.group(1)`.reverse_each do |${1:`!p element_name = match.group(1).lstrip('$@') ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) try: wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) snip.rv = wmatch.group(1).lower() except: snip.rv = 'element' `}| $0 end endsnippet snippet "(\S+)\.Each" ".each { || }" r `!p snip.rv=match.group(1)`.each { |${1:`!p element_name = match.group(1).lstrip('$@') ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) try: wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) snip.rv = wmatch.group(1).lower() except: snip.rv = 'element' `}| $0 } endsnippet snippet "(\S+)\.each" ".each do || end" r `!p snip.rv=match.group(1)`.each do |${1:`!p element_name = match.group(1).lstrip('$@') ematch = re.search("([A-Za-z][A-Za-z0-9_]+?)s?[^A-Za-z0-9_]*?$", element_name) try: wmatch = re.search("([A-Za-z][A-Za-z0-9_]+)$", ematch.group(1)) snip.rv = wmatch.group(1).lower() except: snip.rv = 'element' `}| $0 end endsnippet snippet "(\S+)\.Each_?p(air)?" ".each_pair { |,| }" r `!p snip.rv=match.group(1)`.each_pair { |${1:key},${2:value}| $0 } endsnippet snippet "(\S+)\.each_?p(air)?" ".each_pair do |,| end" r `!p snip.rv=match.group(1)`.each_pair do |${1:key},${2:value}| $0 end endsnippet snippet "(\S+)\.sub" ".sub() { }" r `!p snip.rv=match.group(1)`.sub(${1:expression}) { ${2:"replace_with"} } endsnippet snippet "(\S+)\.gsub" ".gsub() { }" r `!p snip.rv=match.group(1)`.gsub(${1:expression}) { ${2:"replace_with"} } endsnippet snippet "(\S+)\.index" ".index { |item| }" r `!p snip.rv=match.group(1)`.index { |${1:item}| ${2:block} } endsnippet snippet "(\S+)\.Index" ".index do |item| ... end" r `!p snip.rv=match.group(1)`.index do |${1:item}| ${0:block} end endsnippet snippet until "until ... end" until ${1:expression} $0 end endsnippet snippet Until "begin ... end until " begin $0 end until ${1:expression} endsnippet snippet while "while ... end" while ${1:expression} $0 end endsnippet snippet While "begin ... end while " begin $0 end while ${1:expression} endsnippet snippet begin "begin ... rescue ... end" begin $1 rescue $0 end endsnippet snippet rescue rescue Exception => e puts e.message puts e.backtrace.inspect ${0:# Rescue} endsnippet snippet "\b(case|sw(itch)?)" "case when ... end" r case ${1:variable} when ${2:expression} $0 end endsnippet snippet class "class def initialize ... end end" class ${1:`!p snip.rv = snip.basename.title().replace('_', '')`} def initialize(${2:*args}) $0 end end endsnippet snippet module "module" module ${1:`!p snip.rv = snip.basename.title().replace('_', '')`} $0 end endsnippet snippet ### =begin $0 =end endsnippet snippet priv "private " m private $0 endsnippet snippet prot "protected" m protected $0 endsnippet # vim: set ts=2 sw=2 expandtab: