14 1 / 2013

A Look at Ruby 2.0

With Ruby 2.0 set to be released on February 24th, exactly on the 20th anniversary of Ruby’s first debut, I decided to write this article to give you a quick rundown of some of the most interesting changes. And if you would like to experiment with this version before the official release, you can do so by following the instructions in this article.

Read more…

08 1 / 2013

Using a Graph Database with Ruby. Part II: Integration

Yes, it is real, it is finally here! The long waited follow-up to the introductory article is here, just in time for the new year!

In the first article, we learned about graph databases, their differences and advantages over traditional databases, and about Neo4j. In this article, we are going to install Neo4j, integrate and evaluate the gems listed in the first part of this series.

The scenario that we are going to be working with is the continuation of the simple idea in the first article, a social networking example that is capable of producing traversal queries such as “given the fact that Bob is my friend, give me all friends that are friend’s of friend’s of friend’s of Bob”.

Read more…

16 6 / 2012

Check out the interesting article “Using a Graph Database with Ruby. Part I: Introduction" I wrote for the blog RubySource.com. It covers the basics of Graph databases, how it differs from traditional databases, and how it can be used with Ruby.

29 5 / 2012

Obscenity, a profanity filter for Ruby, ActiveModel, and Rack.

Obscenity is a profanity filter gem for Ruby/Rubinius, Rails (through ActiveModel), and Rack middleware.

What that means is that you can use Obscenity in plain Ruby or Rubinius, use it to validate and sanitize attributes in your models through ActiveModel (ActiveRecord, MongoMapper, Mongoid, etc), and use the Rack middleware to automatically reject requests that include profane parameters or sanitize those values before they reach your Application.

Enough said, let’s see some action!

Read More

22 5 / 2012

Adding extra sauce to the profanity_filter Ruby gem

I’ve been using the profanity_filter gem off and on for quite a while now and yes, I know it’s a bit old now but it gets the job done. In this post I’ll share a couple of simple yet “extra sauce” that I added to the gem to make it a bit more useful for both pre and post Rails 3.0.

Adding model validation with validates_profanity_of for Rails < 3.0

One thing that I needed that the gem didn’t “natively” provide was a simple way to do profanity validation on an attribute. I could use a custom validate method every time I needed to check wether or not an attribute was profane but that would require me to duplicate the code on different models, not a clean way.

What I did instead was actually extend the gem’s functionality to add a simple validates_profanity_of method that behaved similar to other ActiveRecord’s validation methods:

Read More

16 5 / 2012

Interview challenge: Ruby method chaining

I’m going to start my first post with an interview challenge that I presented to candidates while working at one of my past employers. This tested the understanding of method chaining, blocks and metaprogramming in Ruby.

The challenge was:

Develop the class structure for the following code:

Interpreter.new { at("7pm").when("tomorrow night").we("John", "Bob").going("drinking") }.output
=> "John and Bob are going drinking tomorrow night at 7pm."

For some, this seems fairly straight-forward, but for others it may seem too advanced or somewhat impossible to do. I’m going to show you step-by-step how to write the class structure for that code and if you don’t already know, you’ll see how simple it is to do method chaining in Ruby. 

Read More

Tags:

Permalink 2 notes