Susan Potter

Snippets

snippets

Ruby Idioms, Part 4

To splat or not to splat, that is the question. In Java to unpack an array's values into separate variables you would need to do something like the following: burgers = [:hamburger, :bocaburger, :gardenburger, :turkeyburger] t = burgers[0] u = burgers[1] v = burgers[2] w = …

snippets

Ruby Idioms, Part 3

Now, probably the biggest difference after the syntax, and the non-static nature of Ruby for Java heads to get used to is that Ruby is an "expressionist" language. Meaning almost all statements in Ruby evaluates to a value, i.e. everything that reasonably can be is an …

snippets

Ruby Idioms, Part 2

Now the "idiom" we will use is not specific to Ruby, since I am pretty sure Perl has one of the constructs we will use to solve the stated problem, but it is still idiomatic, since the majority of popular OO languages (static, dynamic or otherwise) do not have it (as far …

snippets

Ruby Idioms, Part 1

With more people moving to Ruby everyday from languages like Java, I wanted to create blog entries on the most common Ruby idioms (especially ones frequently found in Rails core or Rails application code) and briefly explain how to convert your Java mindset to Ruby (over time). …

snippets

Rubyisms: reopening classes

Ever wished you could write code in a very expressive way like the following examples? expiration_date = 3.years.from_now birth_date = 32.years.ago Now you can, in Ruby at least. Two years ago I was a very happy Python developer that thought no other language could compete …

snippets

Rubyisms: naming conventions

Today I wanted to show the implicit and explicit naming conventions in Ruby for newbies. It isn't particularly consistent with another language's conventions, so could cause confusion when reading the Ruby Standard Library (RSL). Where appropriate I also discuss how some …

snippets

Rubyisms: forwardables

Recently some Java friends of mine have decided to taste the juicier fruits in Ruby-land with my assistance. So below are some excerpts from an email conversation I had with one about Ruby's standard library forwardable features: Suppose we have the following model classes …