├── .gitignore ├── README ├── eruby-rails_view.snippets ├── eruby.snippets ├── install.sh ├── ruby-factory_girl.snippets ├── ruby-rails.snippets ├── ruby-rails_controller.snippets ├── ruby-rails_migration.snippets ├── ruby-rails_model.snippets ├── ruby-rspec.snippets ├── ruby-rspec_rails.snippets ├── ruby-rspec_shoulda_controller.snippets ├── ruby-rspec_shoulda_model.snippets ├── ruby-shoulda.snippets ├── ruby-testunit.snippets └── ruby.snippets /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *~ 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | snipMate is a cool plugin for vim: http://www.vim.org/scripts/script.php?script_id=2540 2 | 3 | Here is some ruby snippets for vim's plugin snipMate. 4 | -------------------------------------------------------------------------------- /eruby-rails_view.snippets: -------------------------------------------------------------------------------- 1 | # Rails View 2 | 3 | snippet h 4 | <%= h ${1} %> 5 | snippet contf 6 | <% content_for :${1:yield_label_in_layout} do -%> 7 | ${2} 8 | <% end -%> 9 | 10 | # form 11 | snippet ff 12 | <% form_for @${1:model} do |f| -%> 13 | <%= f.error_messages %> 14 | <%= f.submit "${2:button}" %> 15 | <% end -%> 16 | snippet ffff 17 | <%= f.file_field :${1:attribute} %> 18 | snippet ffhf 19 | <%= f.hidden_field :${1:attribute} %> 20 | snippet ffl 21 | <%= f.label :${1:attribute}, '${2:label}' %> 22 | snippet ffpf 23 | <%= f.password_field :${1:attribute} %> 24 | snippet ffrb 25 | <%= f.radio_button :${1:attribute}, :${2:tag_value} %> 26 | snippet ffs 27 | <%= f.submit "${1:Submit}" %> 28 | snippet ffta 29 | <%= f.text_area :${1:attribute} %> 30 | snippet fftf 31 | <%= f.text_field :${1:attribute} %> 32 | snippet fieldsf 33 | <% fields_for :${1:model}, @${2:model} do |f| -%> 34 | ${3} 35 | <% end -%> 36 | snippet formt 37 | <% form_tag(:action => "${1:action}") do -%> 38 | ${2} 39 | <% end -%> 40 | 41 | snippet =jsit 42 | <%= javascript_include_tag('${1:javascript_filename}') %> 43 | snippet =sslt 44 | <%= stylesheet_link_tag "${1:stylesheet_filename}" %> 45 | 46 | snippet imaget 47 | <%= image_tag "${1:image_path}" %> 48 | snippet lt 49 | <%= link_to '${1:caption}', ${2:path} %> 50 | snippet ltp 51 | <%= link_to '${1:caption}', ${2:model}_path(@${3:instance}) %> 52 | snippet ltpp 53 | <%= link_to '${1:caption}', ${2:model}s_path %> 54 | 55 | snippet renderp 56 | <%= render :partial => '${1:partial}' %> 57 | snippet rendert 58 | <%= render :template => "${1:file}" %> 59 | 60 | -------------------------------------------------------------------------------- /eruby.snippets: -------------------------------------------------------------------------------- 1 | # Eruby 2 | 3 | snippet each 4 | <% ${1:collection}.each do |${2:member}| -%> 5 | ${3} 6 | <% end -%> 7 | snippet = 8 | <%= ${1} %> 9 | snippet - 10 | <% ${1} -%> 11 | snippet if 12 | <% if ${1:cond} -%> 13 | ${2} 14 | <% end -%> 15 | snippet unless 16 | <% unless ${1:cond} -%> 17 | ${2} 18 | <% end -%> 19 | snippet ife 20 | <% if ${1:cond} -%> 21 | ${2} 22 | <% else -%> 23 | ${3} 24 | <% end -%> 25 | snippet unlesse 26 | <% unless ${1:cond} -%> 27 | ${2} 28 | <% else -%> 29 | ${3} 30 | <% end -%> 31 | snippet yield 32 | <%= yield :${1:partial} %> 33 | 34 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -d ~/.vim ]; then 4 | if [ -f ~/.vim/plugin/snipMate.vim ]; then 5 | cp ./*.snippets ~/.vim/snippets/ 6 | echo "Installed snippets successfully :)" 7 | else 8 | echo "Please install snipMate vim plugin first!" 9 | fi 10 | else 11 | echo "Please install Vim first!" 12 | fi 13 | -------------------------------------------------------------------------------- /ruby-factory_girl.snippets: -------------------------------------------------------------------------------- 1 | # Factory girl 2 | 3 | snippet Fd 4 | Factory.define :${1:model} do |factory| 5 | factory.${3:attribute} ${4} 6 | end 7 | snippet Fdc 8 | Factory.define :${1:obj}, :class => ${2:Class} do |factory| 9 | factory.${3:attribute} ${4} 10 | end 11 | snippet bp 12 | ${1:Model}.blueprint do 13 | ${2:attribute} { ${3} } 14 | end 15 | snippet Fsq 16 | Factory.sequence :${1:attribute} do |n| 17 | ${2} 18 | end 19 | snippet S 20 | Sham.${1:attribute} { Faker::${2:Module}.${3:method} } 21 | 22 | snippet F 23 | Factory(:${1:factory})${2} 24 | snippet Fb 25 | Factory.build(:${1:factory})${2} 26 | snippet Fc 27 | Factory.create(:${1:factory}) 28 | snippet Fa 29 | Factory.attributes_for(:${1:factory}) 30 | snippet Fs 31 | Factory.stub(:${1:factory}) 32 | snippet Fw 33 | Factory(:${1:factory}, :${2}) 34 | snippet Fbw 35 | Factory.build(:${1:factory}, :${2}) 36 | 37 | -------------------------------------------------------------------------------- /ruby-rails.snippets: -------------------------------------------------------------------------------- 1 | # Rails 2 | 3 | snippet logi 4 | logger.info { "${1:message}" }${2} 5 | snippet logd 6 | logger.debug { "${1:message}" }${2} 7 | snippet logw 8 | logger.warn { "${1:message}" }${2} 9 | snippet loge 10 | logger.error { "${1:message}" }${2} 11 | snippet logf 12 | logger.fatal { "${1:message}" }${2} 13 | 14 | -------------------------------------------------------------------------------- /ruby-rails_controller.snippets: -------------------------------------------------------------------------------- 1 | # Actionpack controller 2 | 3 | snippet respond_to 4 | respond_to do |wants| 5 | wants.${1:html}${2} 6 | end 7 | snippet wants 8 | wants.${1:js|json|xml|html}${2} 9 | snippet flash 10 | flash[:${1:notice}] = "${2}" 11 | 12 | -------------------------------------------------------------------------------- /ruby-rails_migration.snippets: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaichen/vim-snipmate-ruby-snippets/be64ced1bf780069571f1d8d40a827f2558c96f8/ruby-rails_migration.snippets -------------------------------------------------------------------------------- /ruby-rails_model.snippets: -------------------------------------------------------------------------------- 1 | # ActiveRecord 2 | 3 | # associations 4 | snippet bt 5 | belongs_to :${1} 6 | snippet ho 7 | has_one :${1} 8 | snippet hm 9 | has_many :${1} 10 | snippet habtm 11 | has_and_belongs_to_many :${1} 12 | snippet hmt 13 | has_many :${1:association}, :through => ${2} 14 | 15 | # validations 16 | snippet vpo 17 | validates_presence_of :${1:attribute} 18 | snippet vpos 19 | validates_presence_of :${1:attribute}, :scope => ${2:scope} 20 | snippet vuniq 21 | validates_uniqueness_of :${1:attribute} 22 | snippet vuniqs 23 | validates_uniqueness_of :${1:attribute}, :scope => ${2:scope} 24 | snippet vacc 25 | validates_acceptance_of :${1:attribute} 26 | snippet vass 27 | validates_associated :${1:association} 28 | snippet vconfirm 29 | validates_confirmation_of :${1:attribute} 30 | snippet vexclus 31 | validates_exclusion_of :${1:attribute}, :in => ${2:range} 32 | snippet vformat 33 | validates_format_of :${1:attribute}, :with => /${2:regex}/i 34 | snippet vinclus 35 | validates_inclusion_of :${1:attribute}, :in => ${2:range} 36 | snippet vlength 37 | validates_length_of :${1:attribute}, ${2} 38 | snippet vnumeric 39 | validates_numericality_of :${1:attribute} 40 | 41 | -------------------------------------------------------------------------------- /ruby-rspec.snippets: -------------------------------------------------------------------------------- 1 | # rspec 2 | snippet spechelper 3 | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')${1} 4 | 5 | # describe 6 | snippet des 7 | describe ${1:description}" do 8 | ${2} 9 | end 10 | snippet desc 11 | describe ${1:class} do 12 | before do 13 | ${2} 14 | end 15 | 16 | end 17 | snippet descd 18 | describe ${1:class}, "${2:description}" do 19 | before do 20 | ${3} 21 | end 22 | 23 | end 24 | snippet desd 25 | describe "${1:description}" do 26 | before do 27 | ${2} 28 | end 29 | 30 | end 31 | 32 | # before & after 33 | snippet before- 34 | before(:${1:each}) do 35 | ${2} 36 | end 37 | snippet after- 38 | after(:${1:each}) do 39 | ${2} 40 | end 41 | 42 | # it should 43 | snippet it 44 | it "should ${1:description}" do 45 | ${2} 46 | end 47 | snippet itsh 48 | it "should ${1:description}" do 49 | ${2:model}.should ${3} 50 | end 51 | snippet itshbe 52 | it "should ${1:description}" do 53 | ${2:model}.should be_${3} 54 | end 55 | 56 | # matchers 57 | snippet sheq 58 | ${1:targe}.should == ${2} 59 | snippet shbe 60 | ${1:target}.should be_${2:result} 61 | 62 | -------------------------------------------------------------------------------- /ruby-rspec_rails.snippets: -------------------------------------------------------------------------------- 1 | # Rspec Rails 2 | 3 | snippet itres 4 | it { response.should be_${1} } 5 | snippet itrend 6 | it { response.should render_template(:${1:template}) } 7 | snippet itred 8 | it { response.should redirect_to(${1:path}) } 9 | 10 | -------------------------------------------------------------------------------- /ruby-rspec_shoulda_controller.snippets: -------------------------------------------------------------------------------- 1 | # Shoulda macros for Rspec 2 | 3 | # assign_to 4 | snippet itshat 5 | it { should assign_to(:${1:model}) } 6 | snippet itshnat 7 | it { should_not assign_to(:${1:model}) } 8 | snippet itshatwk 9 | it { should assign_to(:${1:model}).with_kind_of(${2:klass}) } 10 | snippet itshatw 11 | it { should assign_to(:${1:model}).with(@${2}) } 12 | 13 | # filter_param 14 | snippet itshfp 15 | it { should filter_param(:${1:field}) } 16 | 17 | # layout 18 | snippet itshrwl 19 | it { should render_with_layout } 20 | snippet itshnrwl 21 | it { should_not render_with_layout } 22 | 23 | # respond 24 | snippet itshrespw 25 | it { should respond_with(:${1:success|redirect|missing|error}) } 26 | snippet itshrespwc 27 | it { should respond_with_content_type(:${1:xml|csv|atom|yaml|text}) } 28 | 29 | # route 30 | snippet itshroute 31 | it { should route(:${1:method}, "/${2:path}").to(:action => :${3:action}) } 32 | 33 | # session 34 | snippet itshsets 35 | it { should set_session(:${1:message}) } 36 | snippet itshsetst 37 | it { should set_session(:${1:key}).to(${2:value}) } 38 | snippet itshnsets 39 | it { should_not set_session(:${1:key}) } 40 | 41 | # flash 42 | snippet itshsetfl 43 | it { should set_the_flash } 44 | snippet itshsetflt 45 | it { should set_the_flash.to(/${1:message}/i) } 46 | snippet itshnsetfl 47 | it { should_not set_the_flash } 48 | 49 | -------------------------------------------------------------------------------- /ruby-rspec_shoulda_model.snippets: -------------------------------------------------------------------------------- 1 | # Shoulda macros for Rspec 2 | 3 | # association 4 | snippet itshbt shoulda macros for rspec: should_belong_to 5 | it { should belong_to :${1:association} } 6 | snippet itshhabtm shoulda macros for rspec: should_have_and_belong_to_many 7 | it { should have_and_belong_to_many :${1:association} } 8 | snippet itshhm shoulda macros for rspec: should_have_many 9 | it { should have_many :${1:association} } 10 | snippet itshho shoulda macros for rspec: should_have_one 11 | it { should have_one :${1:association} } 12 | 13 | # validate 14 | snippet itshvuniq 15 | it { should validate_uniqueness_of :${1:attribute} } 16 | snippet itshvpre 17 | it { should validate_presence_of :${1:attribute} } 18 | snippet itshvacc 19 | it { should validate_acceptance_of(:${1:attribute}) } 20 | snippet itshvnum 21 | it { should validate_numericality_of(:${1:attribute}) } 22 | snippet itshlengthlm 23 | it { should ensure_length_of(:${1:attribute}). 24 | is_at_least(${2:least}). 25 | is_at_most(${3:most}) } 26 | snippet itshlengthl 27 | it { should ensure_length_of(:${1:attribute}). 28 | is_at_least(${2:least}) } 29 | snippet itshlengtheq 30 | it { should ensure_length_of(:${1:attribute}). 31 | is_equal_to(${2:num}) } 32 | snippet itshinclusion 33 | it { should ensure_inclusion_of(:${1:attribute}).in_range(${2:range}) } 34 | 35 | snippet itshhns 36 | it { should have_named_scope(:${1:scope}). 37 | finding(:conditions => {:${2:cond} => ${3:value}) } 38 | snippet itshhroa 39 | it { should have_readonly_attributes(:${1:attribute}) } 40 | snippet itshhdbc 41 | it { should have_db_column(:${1:column}).of_type(:${2:type}) } 42 | snippet itshnhdbc 43 | it { should_not have_db_column(:${1:column}).of_type(:${2:type}) } 44 | snippet itshhindex 45 | it { should have_index(:${1:index}) } 46 | snippet itshhindexu 47 | it { should have_index(:${1:index}).unique(${2:true}) } 48 | 49 | -------------------------------------------------------------------------------- /ruby-shoulda.snippets: -------------------------------------------------------------------------------- 1 | # Shoulda 2 | 3 | # macros 4 | snippet shc shoulda macros should_change 5 | should_change "${1:expression}" 6 | snippet shcb 7 | should_change "${1:expression}", :by => ${2:by} 8 | snippet shcft 9 | should_change "${1:expression}", :from => ${2:from}, :to => ${3:to} 10 | snippet shnotc 11 | should_not_change "${1:expression}" 12 | 13 | # shoulda validation macros 14 | snippet shalvf 15 | should_allow_values_for :${1:attribute}, ${2} 16 | snippet should_ensure_length_at_least 17 | should_ensure_length_at_least :${1:attribute}, ${2:length} 18 | snippet should_ensure_length_in_range 19 | should_ensure_length_in_range :${1:attribute}, ${2:range} 20 | snippet should_ensure_length_is 21 | should_ensure_length_is :${1:attribute}, ${2:length} 22 | snippet should_ensure_value_in_range 23 | should_ensure_value_in_range :${1:attribute}, ${2:range} 24 | snippet shnal 25 | should_not_allow_values_for :${1:attribute}, ${2:values} 26 | snippet shvacc 27 | should_validate_acceptance_of :${1:attribute} 28 | snippet shvuniq 29 | should_validate_uniqueness_of :${1:attribute} 30 | snippet shvpre 31 | should_validate_presence_of :${1:attribute} 32 | snippet shvnum 33 | should_validate_numericality_of :${1:attribute} 34 | snippet shhdbc 35 | should_have_db_columns :${1:column} 36 | snippet shhdbi 37 | should_have_indices :${1:column} 38 | snippet shhclm 39 | should_have_class_methods :${1:method} 40 | snippet shhim 41 | should_have_instance_methods :${1:method} 42 | snippet shhns 43 | should_have_named_scope :${1:named_scope}, :conditions => {:${2:cond} => ${3:cond_val}} 44 | snippet shhroa 45 | should_have_readonly_attributes :${1:attribute} 46 | 47 | # shoulda association macros 48 | snippet shbt 49 | should_belong_to :${1:association} 50 | snippet shhabtm 51 | should_have_and_belong_to_many :${1:association} 52 | snippet shhm 53 | should_have_many :${1:association} 54 | snippet shho 55 | should_have_one :${1:association} 56 | 57 | # shoulda controller macros 58 | snippet shass 59 | should_assign_to :${1} 60 | snippet shnass 61 | should_not_assign_to :${1} 62 | snippet shfl 63 | should_set_the_flash_to /${1}/i 64 | snippet shnfl 65 | should_not_set_the_flash ${1} 66 | snippet shss 67 | should_set_session(:${1:key}) { ${2} } 68 | snippet shflp 69 | should_filter_params :${1:password} 70 | snippet shred 71 | should_redirect_to "${1}" 72 | snippet shrend 73 | should_render_template :${1} 74 | snippet shrewol 75 | should_render_without_layout :${1} 76 | snippet shres 77 | should_respond_with :${1:success} 78 | snippet shroute 79 | should_route :${1:method}, "${2:path}", :action => :${3} 80 | 81 | # Shoulda view macros 82 | snippet shrenderaform 83 | should_render_a_form 84 | snippet shrender_page_with_metadata 85 | should_render_page_with_metadata :${1:meta} => ${2:content} 86 | 87 | # shoulda contexts 88 | snippet cont 89 | context "${1:description}" do 90 | setup do 91 | ${2} 92 | end 93 | end 94 | snippet sh 95 | should "${1:description}" do 96 | ${2} 97 | end 98 | 99 | -------------------------------------------------------------------------------- /ruby-testunit.snippets: -------------------------------------------------------------------------------- 1 | # TestUnit 2 | 3 | snippet tc 4 | require \"test/unit\" 5 | 6 | require \"${1:library_file_name}\" 7 | 8 | class Test${2:$1} < Test::Unit::TestCase 9 | def test_${3:case_name} 10 | ${4} 11 | end 12 | end 13 | snippet ts 14 | require \"test/unit\" 15 | 16 | require \"tc_${1:test_case_file}\" 17 | require \"tc_${2:test_case_file}\"${3} 18 | snippet as 19 | assert(${1:test}, \"${2:Failure message.}\")${3} 20 | snippet ase 21 | assert_equal(${1:expected}, ${2:actual})${3} 22 | snippet asne 23 | assert_not_equal(${1:unexpected}, ${2:actual})${3} 24 | snippet asid 25 | assert_in_delta(${1:expected_float}, ${2:actual_float}, ${3:2 ** -20})${4} 26 | snippet asio 27 | assert_instance_of(${1:ExpectedClass}, ${2:actual_instance})${3} 28 | snippet asko 29 | assert_kind_of(${1:ExpectedKind}, ${2:actual_instance})${3} 30 | snippet asn 31 | assert_nil(${1:instance})${2} 32 | snippet asnn 33 | assert_not_nil(${1:instance})${2} 34 | snippet asm 35 | assert_match(/${1:expected_pattern}/, ${2:actual_string})${3} 36 | snippet asnm 37 | assert_no_match(/${1:unexpected_pattern}/, ${2:actual_string})${3} 38 | snippet aso 39 | assert_operator(${1:left}, :${2:operator}, ${3:right})${4} 40 | snippet asr 41 | assert_raise(${1:Exception}) { ${2} } 42 | snippet asnr 43 | assert_nothing_raised(${1:Exception}) { ${2} } 44 | snippet asrt 45 | assert_respond_to(${1:object}, :${2:method})${3} 46 | snippet ass assert_same(..) 47 | assert_same(${1:expected}, ${2:actual})${3} 48 | snippet ass assert_send(..) 49 | assert_send([${1:object}, :${2:message}, ${3:args}])${4} 50 | snippet asns 51 | assert_not_same(${1:unexpected}, ${2:actual})${3} 52 | snippet ast 53 | assert_throws(:${1:expected}) { ${2} } 54 | snippet asnt 55 | assert_nothing_thrown { ${1} } 56 | 57 | -------------------------------------------------------------------------------- /ruby.snippets: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/ruby 2 | snippet #! 3 | #!/usr/bin/ruby 4 | 5 | snippet =b 6 | =begin rdoc 7 | ${1} 8 | =end 9 | snippet y 10 | :yields: ${1:arguments} 11 | snippet rb 12 | #!/usr/bin/env ruby -wKU 13 | 14 | snippet req 15 | require "${1}"${2} 16 | snippet # 17 | # => 18 | snippet end 19 | __END__ 20 | 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 if 30 | if ${1:condition} 31 | ${2} 32 | end 33 | snippet ife 34 | if ${1:condition} 35 | ${2} 36 | else 37 | ${3} 38 | end 39 | snippet elsif 40 | elsif ${1:condition} 41 | ${2} 42 | snippet unless 43 | unless ${1:condition} 44 | ${2} 45 | end 46 | snippet while 47 | while ${1:condition} 48 | ${2} 49 | end 50 | snippet until 51 | until ${1:condition} 52 | ${2} 53 | end 54 | 55 | # Class and Module 56 | snippet cla class .. end 57 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} 58 | ${2} 59 | end 60 | snippet cla class .. initialize .. end 61 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} 62 | def initialize(${2:args}) 63 | ${3} 64 | end 65 | 66 | 67 | end 68 | snippet cla class .. < ParentClass .. initialize .. end 69 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} < ${2:ParentClass} 70 | def initialize(${3:args}) 71 | ${4} 72 | end 73 | 74 | 75 | end 76 | snippet cla ClassName = Struct .. do .. end 77 | ${1:`substitute(Filename(), '^.', '\u&', '')`} = Struct.new(:${2:attr_names}) do 78 | def ${3:method_name} 79 | ${4} 80 | end 81 | 82 | 83 | end 84 | snippet cla class BlankSlate .. initialize .. end 85 | class ${1:BlankSlate} 86 | instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ } 87 | snippet cla class << self .. end 88 | class << ${1:self} 89 | ${2} 90 | end 91 | # class .. < DelegateClass .. initialize .. end 92 | snippet cla- 93 | class ${1:`substitute(Filename(), '^.', '\u&', '')`} < DelegateClass(${2:ParentClass}) 94 | def initialize(${3:args}) 95 | super(${4:del_obj}) 96 | 97 | ${5} 98 | end 99 | 100 | 101 | end 102 | snippet mod module .. end 103 | module ${1:`substitute(Filename(), '^.', '\u&', '')`} 104 | ${2} 105 | end 106 | snippet mod module .. module_function .. end 107 | module ${1:`substitute(Filename(), '^.', '\u&', '')`} 108 | module_function 109 | 110 | ${2} 111 | end 112 | snippet mod module .. ClassMethods .. end 113 | module ${1:`substitute(Filename(), '^.', '\u&', '')`} 114 | module ClassMethods 115 | ${2} 116 | end 117 | 118 | module InstanceMethods 119 | 120 | end 121 | 122 | def self.included(receiver) 123 | receiver.extend ClassMethods 124 | receiver.send :include, InstanceMethods 125 | end 126 | end 127 | 128 | # attr_reader 129 | snippet r 130 | attr_reader :${1:attr_names} 131 | # attr_writer 132 | snippet w 133 | attr_writer :${1:attr_names} 134 | # attr_accessor 135 | snippet rw 136 | attr_accessor :${1:attr_names} 137 | 138 | # include Enumerable 139 | snippet Enum 140 | include Enumerable 141 | 142 | def each(&block) 143 | ${1} 144 | end 145 | # include Comparable 146 | snippet Comp 147 | include Comparable 148 | 149 | def <=>(other) 150 | ${1} 151 | end 152 | # extend Forwardable 153 | snippet Forw- 154 | extend Forwardable 155 | 156 | snippet def 157 | def ${1:method_name} 158 | ${2} 159 | end 160 | snippet deft 161 | def test_${1:case_name} 162 | ${2} 163 | end 164 | # def self 165 | snippet defs 166 | def self.${1:class_method_name} 167 | ${2} 168 | end 169 | # def method_missing 170 | snippet defmm 171 | def method_missing(meth, *args, &blk) 172 | ${1} 173 | end 174 | snippet defd 175 | def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name} 176 | snippet defds 177 | def_delegators :${1:@del_obj}, :${2:del_methods} 178 | snippet am 179 | alias_method :${1:new_name}, :${2:old_name} 180 | 181 | snippet app 182 | if __FILE__ == $PROGRAM_NAME 183 | ${1} 184 | end 185 | # usage_if() 186 | snippet usai 187 | if ARGV.${1} 188 | abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3} 189 | end 190 | # usage_unless() 191 | snippet usau 192 | unless ARGV.${1} 193 | abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3} 194 | end 195 | 196 | snippet array 197 | Array.new(${1:10}) { |${2:i}| ${3} } 198 | snippet hash 199 | Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${3} } 200 | snippet file File.foreach() { |line| .. } 201 | File.foreach(${1:"path/to/file"}) { |${2:line}| ${3} } 202 | snippet file File.read() 203 | File.read(${1:"path/to/file"})${2} 204 | snippet Dir Dir.global() { |file| .. } 205 | Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${3} } 206 | snippet Dir Dir[".."] 207 | Dir[${1:"glob/**/*.rb"}]${2} 208 | snippet dir 209 | Filename.dirname(__FILE__) 210 | 211 | snippet deli 212 | delete_if { |${1:e}| ${2} } 213 | snippet fil 214 | fill(${1:range}) { |${2:i}| ${3} } 215 | # flatten_once() 216 | snippet flao 217 | inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}${3} 218 | snippet zip 219 | zip(${1:enums}) { |${2:row}| ${3} } 220 | # downto(0) { |n| .. } 221 | snippet dow 222 | downto(${1:0}) { |${2:n}| ${3} } 223 | snippet ste 224 | step(${1:2}) { |${2:n}| ${3} } 225 | snippet tim 226 | times { |${1:n}| ${2} } 227 | snippet upt 228 | upto(${1:1.0/0.0}) { |${2:n}| ${3} } 229 | snippet loo 230 | loop { ${1} } 231 | 232 | snippet ea 233 | each { |${1:e}| ${2} } 234 | snippet eab 235 | each_byte { |${1:byte}| ${2} } 236 | snippet eac- each_char { |chr| .. } 237 | each_char { |${1:chr}| ${2} } 238 | snippet eac- each_cons(..) { |group| .. } 239 | each_cons(${1:2}) { |${2:group}| ${3} } 240 | snippet eai 241 | each_index { |${1:i}| ${2} } 242 | snippet eak 243 | each_key { |${1:key}| ${2} } 244 | snippet eal 245 | each_line { |${1:line}| ${2} } 246 | snippet eap 247 | each_pair { |${1:name}, ${2:val}| ${3} } 248 | snippet eas- 249 | each_slice(${1:2}) { |${2:group}| ${3} } 250 | snippet eav 251 | each_value { |${1:val}| ${2} } 252 | snippet eawi 253 | each_with_index { |${1:e}, ${2:i}| ${3} } 254 | snippet reve 255 | reverse_each { |${1:e}| ${2} } 256 | snippet inj 257 | inject(${1:init}) { |${2:mem}, ${3:var}| ${4} } 258 | snippet map 259 | map { |${1:e}| ${2} } 260 | snippet mapwi- 261 | enum_with_index.map { |${1:e}, ${2:i}| ${3} } 262 | 263 | snippet sor 264 | sort { |a, b| ${1} } 265 | snippet sorb 266 | sort_by { |${1:e}| ${2} } 267 | snippet ran 268 | sort_by { rand } 269 | 270 | snippet all 271 | all? { |${1:e}| ${2} } 272 | snippet any 273 | any? { |${1:e}| ${2} } 274 | snippet cl 275 | classify { |${1:e}| ${2} } 276 | snippet col 277 | collect { |${1:e}| ${2} } 278 | snippet det 279 | detect { |${1:e}| ${2} } 280 | snippet fet 281 | fetch(${1:name}) { |${2:key}| ${3} } 282 | snippet fin 283 | find { |${1:e}| ${2} } 284 | snippet fina 285 | find_all { |${1:e}| ${2} } 286 | snippet gre 287 | grep(${1:/pattern/}) { |${2:match}| ${3} } 288 | snippet sub 289 | ${1:g}sub(${2:/pattern/}) { |${3:match}| ${4} } 290 | snippet sca 291 | scan(${1:/pattern/}) { |${2:match}| ${3} } 292 | snippet max 293 | max { |a, b|, ${1} } 294 | snippet min 295 | min { |a, b|, ${1} } 296 | snippet par 297 | partition { |${1:e}|, ${2} } 298 | snippet rej 299 | reject { |${1:e}|, ${2} } 300 | snippet sel 301 | select { |${1:e}|, ${2} } 302 | snippet lam 303 | lambda { |${1:args}| ${2} } 304 | snippet do 305 | do |${1:variable}| 306 | ${2} 307 | end 308 | snippet : 309 | :${1:key} => ${2:"value"}${3} 310 | snippet ope 311 | open(${1:"path/or/url/or/pipe"}, "${2:w}") { |${3:io}| ${4} } 312 | # path_from_here() 313 | snippet patfh 314 | File.join(File.dirname(__FILE__), *%2[${1:rel path here}])${2} 315 | # unix_filter {} 316 | snippet unif 317 | ARGF.each_line${1} do |${2:line}| 318 | ${3} 319 | end 320 | # option_parse {} 321 | snippet optp 322 | require "optparse" 323 | 324 | options = {${1:default => "args"}} 325 | 326 | ARGV.options do |opts| 327 | opts.banner = \"Usage: #{File.basename($PROGRAM_NAME)} 328 | snippet opt 329 | opts.on( "-${1:o}", "--${2:long-option-name}", ${3:String}, 330 | "${4:Option description.}") do |${5:opt}| 331 | ${6} 332 | end 333 | 334 | snippet fl 335 | flunk("${1:Failure message.}")${2} 336 | # Benchmark.bmbm do .. end 337 | snippet bm- 338 | TESTS = ${1:10_000} 339 | Benchmark.bmbm do |results| 340 | ${2} 341 | end 342 | snippet rep 343 | results.report("${1:name}:") { TESTS.times { ${2} }} 344 | # Marshal.dump(.., file) 345 | snippet Md 346 | File.open(${1:"path/to/file.dump"}, "wb") { |${2:file}| Marshal.dump(${3:obj}, $2) }${4} 347 | # Mashal.load(obj) 348 | snippet Ml 349 | File.open(${1:"path/to/file.dump"}, "rb") { |${2:file}| Marshal.load($2) }${3} 350 | # deep_copy(..) 351 | snippet deec 352 | Marshal.load(Marshal.dump(${1:obj_to_copy}))${2} 353 | snippet Pn- 354 | PStore.new(${1:"file_name.pstore"})${2} 355 | snippet tra 356 | transaction(${1:true}) { ${2} } 357 | # xmlread(..) 358 | snippet xml- 359 | REXML::Document.new(File.read(${1:"path/to/file"}))${2} 360 | # xpath(..) { .. } 361 | snippet xpa 362 | elements.each(${1:"//Xpath"}) do |${2:node}| 363 | ${3} 364 | end 365 | # class_from_name() 366 | snippet clafn 367 | split("::").inject(Object) { |par, const| par.const_get(const) } 368 | # singleton_class() 369 | snippet sinc 370 | class << self; self end 371 | snippet nam 372 | namespace :${1:`Filename()`} do 373 | ${2} 374 | end 375 | snippet tas 376 | desc "${1:Task description}" 377 | task :${2:task_name => [:dependent, :tasks]} do 378 | ${3} 379 | end 380 | 381 | --------------------------------------------------------------------------------