Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How to build gems for Rails
Search
naoty
January 31, 2013
Programming
1
170
How to build gems for Rails
naoty
January 31, 2013
Tweet
Share
More Decks by naoty
See All by naoty
Modular API Client
naoty
1
420
Repository pattern in Swift
naoty
3
6.4k
Timepiece
naoty
0
3.6k
Contribution to Rails
naoty
0
4.4k
久々のRailsプロジェクトで導入した開発環境
naoty
2
1.1k
Report of DIYish programming activity
naoty
1
260
Qiita/Kobito vs ?
naoty
0
200
Other Decks in Programming
See All in Programming
Web Components で実現する Hotwire とフロントエンドフレームワークの橋渡し / Bridging with Web Components
da1chi
2
1.4k
Let's Write a Train Tracking Algorithm
twocentstudios
0
220
AIで開発生産性を上げる個人とチームの取り組み
taniigo
0
130
議事録の要点整理を自動化! サーバレス Bot 構築術
penpeen
3
1.6k
Build your own WebP codec in Swift
kishikawakatsumi
2
860
GraphQL×Railsアプリのデータベース負荷分散 - 月間3,000万人利用サービスを無停止で
koxya
1
1k
フロントエンド開発に役立つクライアントプログラム共通のノウハウ / Universal client-side programming best practices for frontend development
nrslib
7
3.8k
AIを活用したレシート読み取り機能の開発から得られた実践知 / AI Receipt Scan Practice
rockname
2
1.5k
CSC509 Lecture 01
javiergs
PRO
1
430
猫と暮らすネットワークカメラ生活🐈 ~Vision frameworkでペットを愛でよう~ / iOSDC Japan 2025
yutailang0119
0
210
dynamic!
moro
9
5.2k
defer f()とdefer fの挙動を 誤解していた話
kogamochiduki
2
160
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
3
160
Scaling GitHub
holman
463
140k
Visualization
eitanlees
148
16k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
The Straight Up "How To Draw Better" Workshop
denniskardys
237
140k
The Power of CSS Pseudo Elements
geoffreycrofte
78
6k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Designing for humans not robots
tammielis
254
25k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Facilitating Awesome Meetings
lara
56
6.6k
Transcript
How to build gems for Rails @naoty_k 131݄31༵
@naoty_k • Ruby on Rails (2010~) • Android (2012.5~) •
iOS (2012.10~) • vimmer!!! • curl http://cui-about.me/naoty 131݄31༵
Talk about... w1BSBNT*ORVJSFSʹ͍ͭͯ w3BJMTʹΈࠐΉ(FNʹඞཁͳͷ wιʔείʔυΛಡΜͰ্͍͘Ͱඞཁͳ 5JQT 131݄31༵
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 131݄31༵
ParamsInquirer on Rails def index if params[:status].accepted? # ... elsif
params[:status].rejected? # ... end end 131݄31༵
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 131݄31༵
action_controller/base.rb module ActionController class Base < Metal # ... ActiveSupport.run_load_hooks(:action_controller,
self) end end 131݄31༵
lib/params_inquirer.rb if defined?(Rails) require ‘params_inquirer/railtie’ else require ‘params_inquirer/parameters’ end 131݄31༵
ActiveSupport::Concern module M def self.included(self) base.extend ClassMethods scope :disabled, where(disabled:
true) end module ClassMethods # ... end end 131݄31༵
ActiveSupport::Concern module M extend ActiveSupport::Concern included do scope :disabled, where(disabled:
true) end module ClassMethods # ... end end 131݄31༵
ActiveSupport::Autoload autoload(:Hoge, ‘hoge’) # ‘hoge.rb‘͜ͷ࣌Ͱrequire͞Ε͍ͯͳ͍ p Hoge # ͜͜Ͱ‘hoge.rb’͕require͞ΕΔ extend
ActiceSupport::Autoload autoload :Fuga p Fuga # ͜͜Ͱ‘fuga.rb’͕require͞ΕΔ 131݄31༵