I’ve recently been writing a program I call RubyBrew in - and this won’t come as a surprise - Ruby. I’ve spent a lot of time learning purely front-end stuff over the past year and I felt like doing something new. In the middle of last year I went to a Ruby on Rails installfest and managed to get a very basic Rails app up and running. However, not knowing anything about Ruby at all, it wasn’t the easiest thing in the world to follow. So, before returning to Rails, I thought it would be a good idea to cut down on the learning curve by spending some time getting to know Ruby by itself.

As one of my other hobbies is making beer, I decided to make a basic inventory manager for my brewing rig. This would be able to keep track of what consumable items (like malt, hops and yeast) I have in stock, as well as a list of recipes. You can take the idea further by having options to tell it you’re brewing a particular recipe and have the program automatically deduct the consumables used from your stock inventory. I also want to include an algorithm that will go through the stock inventory available and present you with a list of recipes you can make with what’s on hand.

All of this is getting a bit ahead of myself at the moment, though. It’s been a fun learning challenge just getting some really basic functionality happening. I hadn’t really done any OO development for a long time (over ten years - and that was in C++) before starting this project, so you can imagine that there’s been a lot of back-tracking and re-writes to the various classes and their methods.

For what I’m going to laughably call the “database” I’m essentially using a couple of arrays. I know, I know. But it doesn’t need to be super fast, as the average brewer won’t have more than a hundred or so items at any given point (at least I don’t, and I’m probably the only one who’ll ever use this thing).

The functionality of the program is pretty basic at the moment and is still very much under active development. As it currently stands, it is run from the command line and uses the HighLine gem to simplify the task of getting a menu structure working. The database is serialised using the YAML module and stored in a file on program exit. At program start, the file is read back and used to re-create the DB objects.

1. View Database
2. Add to Database
3. Modify an Item
4. Exit
What would you like to do?

Once run, the user is presented with a number of options, which will be expanded upon as I continue to work on the project. Obviously, selecting ‘view database’ just dumps the DB object to the screen. Much more interesting to write has been the functions that allow the user to modify the DB by following various prompts and inputting data. Once all the data have been collected together, they are used to create new Recipe or Consumable objects and inserted into the DB.

Just getting this basic stuff working has taught me a huge amount about Ruby, and I have to say I can see why people like it. Coming from a C/C++ background, it took me a little while to get into the Ruby way of thinking (and I still haven’t quite settled into a consistent style with the syntax), but once I understood how it all fit together, I found writing it to be quite straight-forward.

The huge Ruby community is another boon. I can use gems from all over to drammatically cut down the amount of bespoke code I have to write (HighLine being a prime example); and debug tools like Pry are also excellent. But the best thing would have to be the staggering number of helpful sites on the ‘net with great example code, tips, tutorials, and everything in between.