Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This gem is to show how to create a gem from start and to provide an example for creating a gem.

License

Notifications You must be signed in to change notification settings

liukgg/example_gem

Repository files navigation

example_gem

README-中文版

This gem is to show how to create a gem from start and to provide an example for creating a gem.

How to create a gem

You can create a gem by this command:

bundle gem example_gem

Traditionally the summary is like the description but shorter. The summary is normally about one line, while the description can go on for four or five lines.

Make sure to replace "FIXME" and "TODO" in the descriptions - " gem build" doesnʼt like them and they look bad to users.

Youʼll need to add dependencies at the bottom. They can look like this:

 gem.add_development_dependency "rspec"
 gem.add_runtime_dependency "rest-client"
 gem.add_runtime_dependency "some_gem", "1.3.0"
 gem.add_runtime_dependency "other_gem", ">0.8.2"

Each of these adds a runtime dependency (needed to run the gem at all) or a development dependency (needed to develop or test the gem).

Letʼs build your gem and install it:

 gem build example_gem.gemspec
 gem install example_gem-0.0.1.gem

the final step is to require the gem and use it:

% irb
2.1.1 :001 > require 'example_gem'
true
2.1.1 :002 > ExampleGem::Hello.say_hi
Hello, world!
nil
2.1.1 :003 > ExampleGem::Hello.say_hi("liukgg")
Hello, liukgg!
nil
2.1.1 :004 >

How to rebuild and reinstall when you change the code of the gem

Build the gem again and install it:

gem build example_gem.gemspec
gem install example_gem-0.0.1.gem

To know how to publish your gem to rubygems.org, you can see this:

http://guides.rubygems.org/make-your-own-gem/

Materails

《RebuildingRailsCurrent》

http://guides.rubygems.org/make-your-own-gem/

About

This gem is to show how to create a gem from start and to provide an example for creating a gem.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /