Making your own RubyGems!
puts "Hello again RocHack"
- The guy in the above photo is Matz, creator of Ruby.
- He designed the language so that it would be enjoyable to program in.
- Specifically, it has a concise, flexible interface, along with a very positive community.
- RubyGems hosts Ruby libraries, called gems. Gems are optimized to be super-portable, make versioning code easy, and best of all they are totally free to use (both for downloading/installing code, or uploading gems that you made)!
Gem setup tips
On cycle servers, install into
~/bin, avoiding the need to use
that once you do this, you will have to add this folder to your shell’s
path. Make this the default when installing gems by running with the
two commands down below. This will create a
bin folder in your home
directory, and set the default the gem installation location to this folder
cd && mkdir bin echo 'gem: -n~/bin/' >> $HOME/.gemrc
On OSX, the default ruby/gem version needs root access. Some options:
- Use sudo every time you want to install a gem (inconvenient).
echo 'gem: -n/usr/local/bin/' >> $HOME/.gemrc
Try to install a gem, and see if it works:
gem install tv.rb tv.rb --wavy pride
There should be a rainbow in your terminal. Press Control-C to stop!
Writing a gem
Here is a good example of a simple Ruby gem: (qrush/hola). Initially, there may seem like there are a much of random files. Each has their place and purprose, though. Here is a brief description of each file/folder you may see in a standard gem:
- Gemspec: gem details (author, license, files)
- Gemfile: listing gem dependencies (bundle)
- Rakefile: automate tasks (ruby + make)
- lib/ where you keep main source code
- bin/ where you put executables (+x)
- spec/ or test/ where you put code tests
More help on building your first gem found here.
Thanks to everyone who came out and listened to me rant about Ruby!