Here is my work for Exercise 46.
I put my project skeleton on Github.
1. Read about how to use all of the things you installed.
A Ruby “gem” is a self-contained library or program. It is distributed by RubyGems, a packet manager. RubyGems makes it easy to install gems and to distribute gems. A gem contains code, documentation, and a gemspec.
NAME.gemspec – a gemspec is a file that contains information for a gem.
bin – bin stands for binaries, it is where the binary (executable) files go!
(bin does NOT stand for ‘garbage bin’ as previously thought…
remember when the trash used to have a /usr/local/bin path?)
doc – this directory is where you put the documentation for your gem
lib – this directory is where you put the code for the gem.
Rakefile – this is the file that the rake program uses to automate tests and generate code
data – this directory is a place to store application data (for example, database, cache, session files).
ext – this directory is for the extensions of your application.
tests – this directory is where you put the tests for the gem
2. Read about the NAME.gemspec file, commonly called a “Gemspec”, and all it has to offer.
See above. We can use a gemspec file to build a Ruby gem.
3. Make a project put code into the module, then get the module working. This means you have to change all the files, directories, and modules with NAME in them to the name of your project.
I copied the skeleton directory, then changed all the files and directory with NAME into a project name, I just used konnichiwa(means “Good afternoon” in Japanese). I added a simple Konnichiwa class to the konnichiwa.rb file in the library directory. This class has a function hi, that prints “Good Afternoon!” to the screen.
4. Put a script in the bin directory that you can run. Read about how you can make a Ruby script that’s runnable for your system.
I followed this example to run ‘puts “Hello World”‘! Thanks to Commander Coriander.
5. Mention the bin script you created in your Gemspec so that it gets installed.
Under spec.executables, we add the name of the script we created in bin.
6. Use your Gemspec to install your own module and make sure it works, then use gem to uninstall it.
Wow, this was a difficult exercise. Although I successfully made and installed my very first Ruby gem, the whole process was quite confusing. When I tried to uninstall it, it couldn’t find the path to the gem. (The gem was in the directory ruby-2.0.0-p247). I thought I could uninstall from the global gemset, but it said my PATH was not properly set up. It did say I could fix it temporarily in the session by saying use ruby-2.0.0-p247, which is how I successfully uninstalled the gem. I checked that the gem was no longer available by opening interactive ruby, and typed require ‘konnichiwa’. Yep, no such file!
This exercise was about creating a project skeleton with directories and files. This skeleton can be easily used in the future to start a project. A gemspec is a file that contains information about a Ruby gem and can be used to create a Ruby gem. We can make a Ruby script that’s runnable by the system by telling the computer we want it to run the script in a Ruby environment. Even though I still feel everything is ‘magical’, I’m going to give myself a pat on the back for making my first Ruby gem. Boom!
Last but not least, bin stands for binaries. Not garbage bin.