Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to build gems for Rails

naoty
January 31, 2013

How to build gems for Rails

naoty

January 31, 2013
Tweet

More Decks by naoty

Other Decks in Programming

Transcript

  1. @naoty_k • Ruby on Rails (2010~) • Android (2012.5~) •

    iOS (2012.10~) • vimmer!!! • curl http://cui-about.me/naoty 13೥1݄31೔໦༵೔
  2. ParamsInquirer $ gem install params_inquirer $ irb 001 > require

    ‘params_inquirer’ 002 > params = ParamsInquirer::Parameters.new 003 > params[:name] = ‘naoty’ 004 > params[:name].naoty? => true 005 > params[:name].someone? => false 13೥1݄31೔໦༵೔
  3. ParamsInquirer on Rails def index if params[:status].accepted? # ... elsif

    params[:status].rejected? # ... end end 13೥1݄31೔໦༵೔
  4. Railtie class Railtie < ::Rails::Railtie initializer ‘Initialize your gem’ do

    ActiveSupport.on_load(:action_controller) do ::ActionController::Base.send :include, ParamsInquirer::ActionController::Base end end end 13೥1݄31೔໦༵೔
  5. ActiveSupport::Autoload autoload(:Hoge, ‘hoge’) # ‘hoge.rb‘͸͜ͷ࣌఺Ͱ͸require͞Ε͍ͯͳ͍ p Hoge # ͜͜Ͱ‘hoge.rb’͕require͞ΕΔ extend

    ActiceSupport::Autoload autoload :Fuga p Fuga # ͜͜Ͱ‘fuga.rb’͕require͞ΕΔ 13೥1݄31೔໦༵೔