Search Preview
Ruby拡張ライブラリを含むGemのつくりかた | Act as Professional
hiroki.jp今回は拡張ライブラリを含むGemを開発するための流れを学習するために、簡単なgemをつくることにします。簡単なC言語で記述された拡張をGemで配布できる最低限の状態まで構築します。
.jp > hiroki.jp
SEO audit: Content analysis
Language | Error! No language localisation is found. | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Title | Ruby拡張ライブラリを含むGemのつくりかた | Act as Professional | ||||||||||||||||||||||||||||||||||||
Text / HTML ratio | 26 % | ||||||||||||||||||||||||||||||||||||
Frame | Excellent! The website does not use iFrame solutions. | ||||||||||||||||||||||||||||||||||||
Flash | Excellent! The website does not have any flash contents. | ||||||||||||||||||||||||||||||||||||
Keywords cloud | = rake 記事を読む create require extensions ext_example bundle install cd tmpuniversalx86_64darwin14ext_example200 specadd_development_dependency rakecompiler mkdir プログラミング フォローする ext_example001gem GemSpecificationnew Remove spec | ||||||||||||||||||||||||||||||||||||
Keywords consistency |
|
||||||||||||||||||||||||||||||||||||
Headings |
|
||||||||||||||||||||||||||||||||||||
Images | We found 23 images on this web page. |
SEO Keywords (Single)
Keyword | Occurrence | Density |
---|---|---|
= | 13 | 0.65 % |
rake | 11 | 0.55 % |
記事を読む | 10 | 0.50 % |
create | 8 | 0.40 % |
require | 5 | 0.25 % |
extensions | 5 | 0.25 % |
ext_example | 4 | 0.20 % |
bundle | 4 | 0.20 % |
install | 4 | 0.20 % |
cd | 4 | 0.20 % |
tmpuniversalx86_64darwin14ext_example200 | 3 | 0.15 % |
specadd_development_dependency | 3 | 0.15 % |
rakecompiler | 3 | 0.15 % |
mkdir | 3 | 0.15 % |
プログラミング | 3 | 0.15 % |
フォローする | 3 | 0.15 % |
ext_example001gem | 3 | 0.15 % |
GemSpecificationnew | 2 | 0.10 % |
Remove | 2 | 0.10 % |
spec | 2 | 0.10 % |
SEO Keywords (Two Word)
Keyword | Occurrence | Density |
---|---|---|
mkdir p | 3 | 0.15 % |
GemSpecificationnew do | 2 | 0.10 % |
ext_example001gem into | 2 | 0.10 % |
do spec | 2 | 0.10 % |
specsummary = | 2 | 0.10 % |
= qTODO | 2 | 0.10 % |
qTODO Write | 2 | 0.10 % |
Write a | 2 | 0.10 % |
cd tmpuniversalx86_64darwin14ext_example200 | 2 | 0.10 % |
specdescription = | 2 | 0.10 % |
= qC | 2 | 0.10 % |
qC extensions | 2 | 0.10 % |
シェアする ツイート | 2 | 0.10 % |
extensions example | 2 | 0.10 % |
rake compileext_example | 2 | 0.10 % |
Remove any | 2 | 0.10 % |
実際に動作させてみる。 irb | 1 | 0.05 % |
libext_exampleext_examplebundle cp | 1 | 0.05 % |
tmpuniversalx86_64darwin14ext_example200 cd | 1 | 0.05 % |
cp tmpuniversalx86_64darwin14ext_example200ext_examplebundle | 1 | 0.05 % |
SEO Keywords (Three Word)
Keyword | Occurrence | Density | Possible Spam |
---|---|---|---|
= qC extensions | 2 | 0.10 % | No |
GemSpecificationnew do spec | 2 | 0.10 % | No |
qC extensions example | 2 | 0.10 % | No |
qTODO Write a | 2 | 0.10 % | No |
= qTODO Write | 2 | 0.10 % | No |
Act as Professional | 1 | 0.05 % | No |
mkdir p tmpuniversalx86_64darwin14ext_example200 | 1 | 0.05 % | No |
SystemLibraryFrameworksRubyframeworkVersions20usrbinruby I extext_exampleextconfrb | 1 | 0.05 % | No |
tmpuniversalx86_64darwin14ext_example200 SystemLibraryFrameworksRubyframeworkVersions20usrbinruby I | 1 | 0.05 % | No |
cd tmpuniversalx86_64darwin14ext_example200 SystemLibraryFrameworksRubyframeworkVersions20usrbinruby | 1 | 0.05 % | No |
tmpuniversalx86_64darwin14ext_example200 cd tmpuniversalx86_64darwin14ext_example200 | 1 | 0.05 % | No |
p tmpuniversalx86_64darwin14ext_example200 cd | 1 | 0.05 % | No |
rake compileext_example mkdir | 1 | 0.05 % | No |
compileext_example mkdir p | 1 | 0.05 % | No |
extext_exampleextconfrb creating Makefile | 1 | 0.05 % | No |
コンパイルする。 rake compileext_example | 1 | 0.05 % | No |
here コンパイルする。 rake | 1 | 0.05 % | No |
goes here コンパイルする。 | 1 | 0.05 % | No |
code goes here | 1 | 0.05 % | No |
Your code goes | 1 | 0.05 % | No |
SEO Keywords (Four Word)
Keyword | Occurrence | Density | Possible Spam |
---|---|---|---|
= qTODO Write a | 2 | 0.10 % | No |
= qC extensions example | 2 | 0.10 % | No |
Act as Professional フォローする | 1 | 0.05 % | No |
here コンパイルする。 rake compileext_example | 1 | 0.05 % | No |
cd tmpuniversalx86_64darwin14ext_example200 SystemLibraryFrameworksRubyframeworkVersions20usrbinruby I | 1 | 0.05 % | No |
tmpuniversalx86_64darwin14ext_example200 cd tmpuniversalx86_64darwin14ext_example200 SystemLibraryFrameworksRubyframeworkVersions20usrbinruby | 1 | 0.05 % | No |
p tmpuniversalx86_64darwin14ext_example200 cd tmpuniversalx86_64darwin14ext_example200 | 1 | 0.05 % | No |
mkdir p tmpuniversalx86_64darwin14ext_example200 cd | 1 | 0.05 % | No |
compileext_example mkdir p tmpuniversalx86_64darwin14ext_example200 | 1 | 0.05 % | No |
rake compileext_example mkdir p | 1 | 0.05 % | No |
コンパイルする。 rake compileext_example mkdir | 1 | 0.05 % | No |
goes here コンパイルする。 rake | 1 | 0.05 % | No |
SystemLibraryFrameworksRubyframeworkVersions20usrbinruby I extext_exampleextconfrb creating | 1 | 0.05 % | No |
code goes here コンパイルする。 | 1 | 0.05 % | No |
Your code goes here | 1 | 0.05 % | No |
ExtExample Your code goes | 1 | 0.05 % | No |
module ExtExample Your code | 1 | 0.05 % | No |
ext_exampleext_example module ExtExample Your | 1 | 0.05 % | No |
require ext_exampleext_example module ExtExample | 1 | 0.05 % | No |
ext_exampleversion require ext_exampleext_example module | 1 | 0.05 % | No |
Internal links in - hiroki.jp
プログラミング | Act as Professional
アジャイル | Act as Professional
書評 | Act as Professional
プロフィール | Act as Professional
お問い合わせ | Act as Professional
Vornado サーキュレーター もっと早く購入しておけばよかった…。 | Act as Professional
日常 | Act as Professional
ピンボケや手ぶれ写真を機械的に検出する方法 – ポートレート編 | Act as Professional
OpenCV | Act as Professional
Python | Act as Professional
ピンボケや手ぶれ写真を機械的に検出する方法 | Act as Professional
Weather Station 屋外モジュールの電池を交換した | Act as Professional
「リフォーム Rails app」というトークをしてきました | Act as Professional
Ruby | Act as Professional
Ruby on Rails | Act as Professional
元「日本一のニート」が実践する人間味あふれる「知の整理術」 | Act as Professional
fastladderのコミット権をいただいた | Act as Professional
git | Act as Professional
github | Act as Professional
ソフトウェア | Act as Professional
ポストに投函される迷惑なダイレクトメールやチラシの対策 | Act as Professional
ライフハック | Act as Professional
SSL/TLSのバージョン差についてザックリと理解するには | Act as Professional
Linux | Act as Professional
Elixir | Act as Professional
ダークソウルシリーズは挫折したけど、仁王は楽しんでプレイできた | Act as Professional
ゲーム | Act as Professional
バーコードを送るだけで価格を調査するLINE Botを開発したのでご利用ください | Act as Professional
インストール簡単 無料で使えるGitHubのようなGitea | Act as Professional
コードレビュー | Act as Professional
元旦に実施される うるう秒の対策 まとめ | Act as Professional
長年愛されつづけるホットサンドイッチメーカーのバウルーがやってきた!! | Act as Professional
PS4 Pro HDMI 4K/60Hz環境を構築するのに購入検討した4KテレビやPCモニターなど | Act as Professional
cloud-init の設定を上書き、拡張する方法 | Act as Professional
DevOps | Act as Professional
ubuntu | Act as Professional
電子書籍 | Act as Professional
Ruby拡張ライブラリを含むGemのつくりかた | Act as Professional
extensions | Act as Professional
右クリック、ダブルクリック、ドラッグ&ドロップを現在の形にした中島聡氏の著書を読んだ | Act as Professional
書籍 | Act as Professional
4月からの電力自由化するので電力会社を比較して契約した | Act as Professional
MVNO | Act as Professional
Terminalに雪を降らす魔法の1ライナー | Act as Professional
Ruby2.3.0リリース 主な新機能についてサンプルコードとともに紹介 | Act as Professional
WordPressをPHP7.0にバージョンアップ | Act as Professional
Web | Act as Professional
WordPress | Act as Professional
Software Design 「ChatOps」特集に寄稿しました | Act as Professional
お知らせ | Act as Professional
Hiroki.jp Spined HTML
Ruby拡張ライブラリを含むGemのつくりかた | Act as Professional Act as Professional フォローする プログラミング アジャイル 書評 プロフィール お問い合わせ ホームプログラミングRubyextensions Ruby拡張ライブラリを含むGemのつくりかた 2016/6/20 extensions, Ruby, プログラミング シェアする ツイート 今回は拡張ライブラリを含むGemを開発するための流れを学習するために、簡単なgemをつくることにします。 簡単なC言語で記述された拡張をGemで配布できる最低限の状態まで構築します。 スポンサーリンク Gemの雛形を生成する。 $ stow gem ext_example create ext_example/Gemfile create ext_example/Rakefile create ext_example/LICENSE.txt create ext_example/README.md create ext_example/.gitignore create ext_example/ext_example.gemspec create ext_example/lib/ext_example.rb create ext_example/lib/ext_example/version.rb Initializing git repo in /Users/hirocaster/src/github.com/hirocaster/ext_example rake-compiler を導入する ext_example.gemspecを記述する spec.summaryとspec.descriptionは適当に記述する。 spec.extensionsには後程つくるファイルを記述しておく。 @@ -8,8 +8,8 @@ Gem::Specification.new do |spec| spec.version = ExtExample::VERSION spec.authors = ["hirocaster"] spec.email = ["hohtsuka@gmail.com"] - spec.summary = %q{TODO: Write a short summary. Required.} - spec.description = %q{TODO: Write a longer description. Optional.} + spec.summary = %q{C extensions example} + spec.description = %q{C extensions example} spec.homepage = "" spec.license = "MIT" @@ -18,6 +18,9 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] + spec.extensions = %w{ext/ext_example/extconf.rb} + spec.add_development_dependency "bundler", "~> 1.5" spec.add_development_dependency "rake" + spec.add_development_dependency "rake-compiler" end stow installを実行してrake-compilerを導入する。 $ stow install Fetching gem metadata from https://rubygems.org/.. Resolving dependencies... Using bundler (1.5.3) Using ext_example (0.0.1) from source at . Installing rake (11.2.2) Installing rake-compiler (0.9.9) Your stow is complete! Gems in the group production were not installed. I was installed into ./vendor/bundle rake-compilerを稼動させる環境をつくる 拡張ライブラリはextディレクトリ以下に記述していく。 $ mkdir -p ext/ext_example/ $ touch ext/ext_example/extconf.rb extconf.rb にはMakfileを作成するおまじないを記述。 require 'mkmf' create_makefile('ext_example/ext_example') Rakefileに先程のextconf.rbを利用してTaskを定義できるように記述 require "rake/extensiontask" Rake::ExtensionTask.new("ext_example") do |ext| ext.lib_dir = "lib/ext_example" end これでC言語で記述したライブラリをコンパイルするためのTaskが定義されるはずなので、確認する。 $ rake -T rake build # Build ext_example-0.0.1.gem into the pkg directory rake wipe # Remove any temporary products rake clobber # Remove any generated files rake compile # Compile all the extensions rake compile:ext_example # Compile ext_example rake install # Build and install ext_example-0.0.1.gem into system gems rake release # Create tag v0.0.1 and build and push ext_example-0.0.1.gem to Rubygems ここまでの準備でrake compile:ext_exampleなどのタスクが表示されるのを確認できる。 拡張ライブラリを書く 拡張ライブラリの中心となるext/ext_example/ext_example.cを記述する。 Rubyは拡張ライブラリをロードする時に「Init_ライブラリ名」と いう関数を自動的に実行します. https://github.com/ruby/ruby/blob/trunk/doc/extension.ja.rdoc#cコードを書く ということなのでInit_ext_example()を定義。 #include <stdio.h> void Init_ext_example() { puts("Hello World!"); } この拡張をロードするようにlib/ext_example.rbに記述する。 @@ -1,4 +1,5 @@ require "ext_example/version" +require "ext_example/ext_example" module ExtExample # Your lawmaking goes here... コンパイルする。 $ rake compile:ext_example mkdir -p tmp/universal.x86_64-darwin14/ext_example/2.0.0 cd tmp/universal.x86_64-darwin14/ext_example/2.0.0 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -I. ../../../../ext/ext_example/extconf.rb creating Makefile cd - cd tmp/universal.x86_64-darwin14/ext_example/2.0.0 /usr/bin/make compiling ../../../../ext/ext_example/ext_example.c linking shared-object ext_example/ext_example.bundle cd - mkdir -p tmp/universal.x86_64-darwin14/stage/lib/ext_example install -c tmp/universal.x86_64-darwin14/ext_example/2.0.0/ext_example.bundle lib/ext_example/ext_example.bundle cp tmp/universal.x86_64-darwin14/ext_example/2.0.0/ext_example.bundle tmp/universal.x86_64-darwin14/stage/lib/ext_example/ext_example.bundle 実際に動作させてみる。 $ irb irb(main):001:0> require "ext_example" Hello World! => true irb(main):002:0> Hello World!が出力されたので、無事に動作することが確認でききました。 ここまででC言語で記述した拡張を含む、最低限のGemを作成することができました。 拡張ライブラリの処理を実用的にしていくためには Rubyの拡張ライブラリを開発するためのドキュメント が日本語であります。こちらを参考にしていくと、やりたいことをC言語でどのように記述してRubyと連携をとっていけばいいのか理解できるようになると思います。 スポンサーリンク シェアする ツイート フォローする hirocaster 関連記事 Mac10.7.3 Xcode4.3.2 rvm Ruby1.9.3-p194 環境構築 Xcodeとrvmと最新のrubyではめられた感じ満載の@HIROCASTERでございませう。 手元のXcodeがすごく古かったので... 記事を読む ペアプログラミングについてみんなが誤解していること プログラマ1人で完成できる仕事に、2人のプログラマを投入して、直感的に判断してペアプログラミングを拒否する人がいます。これには大きな間... 記事を読む 2011年をふりかえる レトロスペクティブ 2011年最後に日に、今年を個人的にふり返ってみたいと思います。 やはり、ここはアジャイルでいうところのレトロスペクティブで。 記事を読む バーコードを送るだけで価格を調査するLINE Botを開発したのでご利用ください スマホのカメラでバーコードを撮影して送るとAmazon、楽天、Yahoo!ショッピングなどの価格を調査して教えてくれるLINE Bot「価格... 記事を読む 眠った技術書をもういちど読み始めるイベント開催します!! 素晴らしい書籍だと紹介された、熱い思いを抱いて買ったあの本が眠ってませんか? その熱い思いのエピソードを教えてください。 既に読んだ人... 記事を読む Fizz Buzz 問題 プログラムを書けないプログラマを雇うのは雇う側の問題 プログラマの中途募集をしたら、「PHPできます」という技術者が応募してきて、1週間使って、WEBメールフォーム1つすら仕様通りにできなかっ... 記事を読む 本当にありがとう。最後の RubyKaigi2011 #rubykaigi Aaron Patterson (tenderlove) によるペアプログラマー道(動画)から全てが始まる最後の日本Ruby会議... 記事を読む プレゼンの2枚目の写真が重要なイベント第4回Symfony2勉強会を開催しました。 #Symfony2study 運営側として参加しました。 第4回Symfony2勉強会 第1部基礎編 第4回Symfony2勉強会 第2部実践編 第4回Sy... 記事を読む プログラミング問題を求めて Fizz-Buzz問題みたいな数分で解けるプログラミング問題をまとめたものがあったら、ちょっとやってみたいなぁ。と考えて探してみたけど、い... 記事を読む これからソースコードレビューをする人達へ向けての心得 動機編 組織がコードレビューを始める動機や注意しなければいけないことについて考えます。 記事を読む 右クリック、ダブルクリック、ドラッグ&ドロップを現在の形にした中島聡氏の著書を読んだ MONOQLO (モノクロ) 2016年 08月号 読んだ 検索 著者について HIROCASTER アジャイル開発の知識とGitHubを活用し、自動化(インフラ・テスト)・開発ワークフローの効率化を推進するプログラマ。よりくわしくはこちら 著者のSNSなど フォローする 著書 人気記事まだデータがありません。 新着記事 Vornado サーキュレーター もっと早く購入しておけばよかった…。 ピンボケや手ぶれ写真を機械的に検出する方法 – ポートレート編 ピンボケや手ぶれ写真を機械的に検出する方法 Weather Station 屋外モジュールの電池を交換した 「リフォーム Rails app」というトークをしてきました © 2009 Act as Professional