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

gem入門

cottondesu
December 19, 2016

 gem入門

簡単なgemの作り方の説明

cottondesu

December 19, 2016
Tweet

More Decks by cottondesu

Other Decks in Technology

Transcript

  1. 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 ࣮ߦྫ
  2. 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 ˡ௥ه
  3. 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
  4. gem実行 $ bundle install # Thor ͳΜ͔ΛΠϯετʔϧ͢ΔͨΊʹ $ % bundle

    exec exe/exsample_gem hoge Hello world HFNΛ࣮ߦ͢ΔલʹCVOEMFJOTUBMM͕ඞཁ