The past few days I’v taken some time to find out how to create a Ruby Gem. This has been on my to-do list for quite a while, but now I’m able to tick it off.
Well, what did I make?
The first Gem can also be used as a Ruby on Rails plugin and is called ActsAsGold. If you’ve ever played World of Warcraft, you’ll know how the money system works. You have Copper. A 100 Copper is worth 1 Silver. And 100 Silver is worth 1 Gold.
The ActsAsGold Gem allows you to extend your ActiveRecord model with this money system. All you need on your model is an attribute that stores a single integer value.
Let me give you a small tour.
class Player < ActiveRecord::Base acts_as_gold :column => :money end # This will be store like @player.money => 2003652 @player.gold => 200 @player.silver => 36 @player.copper => 52 # You can also easily earn or spend money @player.earn(10.gold + 75.silver) @player.spend(1.gold + 10.silver + 95.copper)
Read more about the Gem, or install the gem right now:
sudo gem install ariejan-acts_as_gold --source http://gems.github.com
The other gem is WarcraftArmory, which is still in early development, so new stuff can and will be added in the future.
WA (WarcraftArmory) allows you to easily retrieve character information from the World of Warcraft Armory. Currently it can retrieve:
- Name of the character
- Name of the characters guild
It works for both EU and US warcraft servers.
require 'warcraft_armory' character = WarcraftArmory.find(:eu, 'Aszune', 'Nosius') character.race => "Human" character.level => 15
Again, simply install the plugin and use it like any other gem or read the README first.
sudo gem install ariejan-warcraft_armory --source http://gems.github.com
Please let me know if you find these gems useful or if you use them in one of your projects.
Want to keep reading and learn more? I've got you
covered with a hand picked selection of awesome books.