Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
gem入門
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
cottondesu
December 19, 2016
Technology
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
gem入門
簡単なgemの作り方の説明
cottondesu
December 19, 2016
Transcript
28 slides
gem 入門 kanazawa.rb meetup#52 2016年12月17日
@cotton_desu
gem作ったことある?
難易度が高い?
それは思い込みです
gemは簡単に作れる
gemとは
• パッケージ化されたRubyアプリケーション • rubyライブラリ • gemコマンドを使って簡単にinstallやremove 等ができる gemとは
CLI系gem作成手順
CLI系gem作成手順 1. bundle gem コマンド実行 2. gemspecファイルに追記 3. exe/<gem名>ファイルに追記 4.
lib/<gem名>.rbに追記 5. lib/<gem名>/cli.rbを作成
CLI系gem作成手順 1. bundle gem コマンド実行 2. gemspecファイルに追記 3. exe/<gem名>ファイルに追記 4.
lib/<gem名>.rbに追記 5. lib/<gem名>/cli.rbを作成
bundle gem コマンド bundle gem <gem໊> -b ҎԼͷίϚϯυΛ࣮ߦ͢Δ
bundle gem コマンド % bundle gem exsample_gem -b Creating gem
'exsample_gem'... MIT License enabled in config Code of conduct enabled in config create exsample_gem/Gemfile create exsample_gem/.gitignore create exsample_gem/lib/exsample_gem.rb create exsample_gem/lib/exsample_gem/version.rb create exsample_gem/exsample_gem.gemspec create exsample_gem/Rakefile create exsample_gem/README.md create exsample_gem/bin/console create exsample_gem/bin/setup create exsample_gem/LICENSE.txt create exsample_gem/CODE_OF_CONDUCT.md create exsample_gem/exe/exsample_gem Initializing git repo in /tmp/exsample_gem ࣮ߦྫ
CLI系gem作成手順 1. bundle gem コマンド実行 2. gemspecファイルに追記 3. exe/<gem名>ファイルに追記 4.
lib/<gem名>.rbに追記 5. lib/<gem名>/cli.rbを作成
gemspecファイル追記 spec.add_dependency 'thor' HFNTQFDʹҎԼΛه͢Δ UIPS3VCZͷ$-*πʔϧͷ࡞Λࢧԉ͢ΔHFN
gemspecファイル追記 FYTBNQMF@HFNHFNTQFDهྫ # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib)
unless $LOAD_PATH.include?(lib) require 'exsample_gem/version' Gem::Specification.new do |spec| spec.name = "exsample_gem" spec.version = ExsampleGem::VERSION —————-লུ—————- spec.add_development_dependency "bundler", "~> 1.11" spec.add_development_dependency "rake", "~> 10.0" spec.add_dependency 'thor' end ˡه
CLI系gem作成手順 1. bundle gem コマンド実行 2. gemspecファイルに追記 3. exe/<gem名>ファイルに追記 4.
lib/<gem名>.rbに追記 5. lib/<gem名>/cli.rbを作成
exe/<gem名>ファイル追記 <※1>::CLI.start ҎԼΛه͢Δ ※1 gem໊ͷ಄ɺ_ͷޙͷจࣈΛେจࣈʹ_Λআ͢Δ ྫ) exsample_gem " ExsampleGem
exe/<gem名>ファイル追記 FYFFYTBNQMF@HFNهྫ #!/usr/bin/env ruby require "exsample_gem" ExsampleGem::CLI.start ˡه
CLI系gem作成手順 1. bundle gem コマンド実行 2. gemspecファイルに追記 3. exe/<gem名>ファイルに追記 4.
lib/<gem名>.rbに追記 5. lib/<gem名>/cli.rbを作成
lib/<gem名>.rb追記 require "<gem໊>/cli" ҎԼΛه͢Δ
lib/<gem名>.rb追記 FYFFYTBNQMF@HFNSCهྫ require "exsample_gem/version" require "exsample_gem/cli" module ExsampleGem # Your
code goes here... end ˡه
CLI系gem作成手順 1. bundle gem コマンド実行 2. gemspecファイルに追記 3. exe/<gem名>ファイルに追記 4.
lib/<gem名>.rbに追記 5. lib/<gem名>/cli.rbを作成
lib/<gem名>/cli.rb作成 def hoge puts "Hello world" end DMJSCΛ৽ن࡞͠ɺػೳΛՃ͢Δ ࠓճIPHFίϚϯυͰ)FMMPXPSMEΛ දࣔ͢Δػೳͱ͢Δ
ίϚϯυϝιουͱͯ͠ఆٛ͢Δ
lib/<gem名>/cli.rb作成 MJCʻHFN໊ʼDMJSC require 'exsample_gem' require 'thor' module ExsampleGem class CLI
< Thor desc "hoge", "Hello world print." #ίϚϯυͷ༻ྫͱɺ֓ཁ def hoge #ίϚϯυϝιουͱͯ͠ఆٛ͢Δ puts "Hello world" end end end
gem実行 $ bundle install # Thor ͳΜ͔ΛΠϯετʔϧ͢ΔͨΊʹ $ % bundle
exec exe/exsample_gem hoge Hello world HFNΛ࣮ߦ͢ΔલʹCVOEMFJOTUBMM͕ඞཁ
作ったgemのDemo
• bundle gemコマンドでほぼ必要な ファイルの雛形が作成される • gemを作るのは難しくない • 気軽にgemを作りましょう 総括
More Decks by cottondesu
See All by cottondesu
在庫管理・買い物メモを作成中/creating-inventory-management-shopping-list
cottondesu
0
23
ヨシケイの撮り忘れを対策したPart2/measures-were-taken-to-prevent-forgetting-to-pick-up-yoshikei-part2
cottondesu
0
58
ヨシケイの取り忘れ対策した / Measures were taken to prevent forgetting to pick up Yoshikei
cottondesu
0
380
開発環境公開ハード編 / Development environment public hardware version
cottondesu
0
200
開発環境公開ソフト編 / Development environment public software edition
cottondesu
0
200
正規表現で心が折れた/Regular expressions broke my heart
cottondesu
0
190
オレオレGASからMakeへの移行を検討してみた / Considering the transition from Ore Ore GAS to Make
cottondesu
0
810
Kanazawa.rb 10周年KPT / Kanazawa.rb 10th Anniversary KPT
cottondesu
0
930
Kanazawa.rb 9周年KPT / Kanazawa.rb 9th Anniversary KPT
cottondesu
0
510
Other Decks in Technology
See All in Technology
「任されビリティ」で引き受けて「よしなりてぃ」に頼らず任せる / Accept tasks with "makasarebility" and hand them over without relying on "yoshinarily"
pauli
1
820
Why start a new company, on Rails and AI, today. SF Ruby Conf 2026, Irina Nazarova
irinanazarova
0
160
マネジメントされる側の仕事は「文句」を言うこと
riyaamemiya
7
5.8k
人の努力に頼らないセキュリティをエンジニアリングする在り方 / An approach to engineering security that does not rely on human effort
carta_engineering
0
220
cdkdがどんだけ早いか、実際に動かして見てみよう
smt7174
1
130
おうち環境でも「なるべく止めたくない!」 ― おうち環境の機器冗長化の理想と現実
yuutosi
1
610
Frontier Teams — Amazon は AI で「開発のやり方」をどう変えたのか
kmotohas
0
300
AIエージェントのアーキテクチャ設計
nsatoh
0
100
自動計装なしでECSサービスをApplication Signalsに載せるまで
ota1022
2
420
Kansai WordPress Meetup@大阪『ブロックテーマを作る上で知っておくべきこと
torounit
0
250
AI-Ready なデータ基盤ってなに? & 新卒未経験が、いま考えていること
imuta
0
780
MCPでネットワーク障害調査を自動化する前に直すべき3つのこと
yama3133
1
630
Featured
See All Featured
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
320
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Building Adaptive Systems
keathley
44
3.3k
ラッコキーワード サービス紹介資料
rakko
5
5.9M
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
850
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
570
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.5k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
Testing 201, or: Great Expectations
jmmastey
46
8.4k