While many people think to learn the regular expression syntax inside and out, it's easy to forget about Regular Expression Options. These options, while not always earth shatteringly useful, can often vastly simplify your regular expressions.
For example, the i option makes your regular expression case insensitive, meaning you don't have to repeat REPEAT yourself YOURSELF to match strings of differing cases. And of course the x option allows you to make extended regular expressions, which can be spread over multiple lines and even contain comments. This option turns unreadable character soup into elegant and well documented code.
The garbage collector is not something many dare to delve into. However, when you're trying to optimize a Ruby application, understanding how and when it's interfering, how many objects you're really creating and how much stress you're putting on the garbage collector is invaluable information. Demystifying the Ruby GC is an excellent blog post outlining all the details.
Ruby has always struggled when it came to client-side programs. There was no good, reliable and modern GUI binding. They come and go, many of the bindings for things like GTK and Qt are often out of date, difficult to compile, and deploying applications based on this is just a pain. Enter JRuby. Java has extensive GUI APIs that are instantly available to you from JRuby, and deploying them is as easy as giving someone a jar file.
We'll take a quick look at building GUI applications using Swing by building an ROT13 encoder.
Code Golf was a big (in the programming community) sport where people complete to see if they can write the shortest program possible to complete a task. This was most popular with Perl, but a new web site has popped up for Ruby code golf: The Ruby Game. While this may seem like the antithesis of many of Ruby's core principals, there's no denying it's a fun diversion and you'll certainly pick up a few tricks you might be able to use.
JRuby is an quite an exciting Ruby interpreter. While some may shy away from it since it runs on the Java VM, something not well liked by many programmers, JRuby is quite interesting and in many cases faster than MRI, the official Ruby interpreter. But this isn't why it's particularly exciting. It's exciting because you have access to the huge library of Java code out there and can use it directly from your Ruby code, without any visible "glue." So we'll install JRuby on Windows and write a very quick GUI application.
JetBrains has released RubyMine version 6. RubyMine is an excellent Ruby IDE I personally used for some time when version 5 was released and was pleasantly surprised at its speed and feature set. RubyMine 6 has a few new features, including the ability to manage multiple projects in the same IDE window, updated Ruby language support, an improved search feature, a faster JRuby debugger, and a host of other features. From my experiences with RubyMine 5, I recommend everyone at least try RubyMine. You may not think you even want an IDE for Ruby, but you may find you were sorely missing out on this great IDE.
I've done it, I sold my Macbook Pro and bought a Surface Pro 2. Thus far, it's been great, but now it's time to get busy with Ruby. I've had mixed experiences with Ruby on Windows in the past and this time I thought I'd give jRuby a go.
JRuby, if you don't know, is a Ruby implementation on the Java runtime environment. Not only does it just run Ruby code, but it also integrates with Java fully, allowing you to use the very large and mature Java codebase and libraries. And, not only that, but those libraries can in turn use your Ruby code. It's a full integration into the Java environment.
So watch this space for jRuby content in the coming days!
Generating QRCodes can be a very useful thing. You can include them in print materials to send people to your web application, or include them in your web application to make it easy for people to access it using their smart phone. You see QRCodes everywhere, but until you try it, you'll never know how easy it is to work with them.
The following are a number of tips that weren't large or significant enough to warrant their own posts. Included are more clear numeric literals, an easy way to make short alphanumeric IDs and an interesting use for conditional assignments.
There are a lot of tricks you can do in Ruby. It's an expressive, dynamic language that can be used (or abused) to create some very expressive constructions. This article outlines one such trick you can use to possibly make your case statements more readable.