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
160
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.3k
久々のRailsプロジェクトで導入した開発環境
naoty
2
1.1k
Report of DIYish programming activity
naoty
1
250
Qiita/Kobito vs ?
naoty
0
200
Other Decks in Programming
See All in Programming
Webからモバイルへ Vue.js × Capacitor 活用事例
naokihaba
0
750
Result型で“失敗”を型にするPHPコードの書き方
kajitack
4
140
KotlinConf 2025 現地で感じたServer-Side Kotlin
n_takehata
1
220
VS Code Update for GitHub Copilot
74th
1
190
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
1
380
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
160
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
44
29k
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
2
210
コード書くの好きな人向けAIコーディング活用tips #orestudy
77web
3
330
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
130
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
150
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
The Pragmatic Product Professional
lauravandoore
35
6.7k
The Cost Of JavaScript in 2023
addyosmani
51
8.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
Code Review Best Practice
trishagee
68
18k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.5k
How to Ace a Technical Interview
jacobian
277
23k
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༵