Aimred Developer Blog RSS feed icon

Rediscovering Ruby: Abbrev

The Ruby API is full of hidden-in-plain-sight libraries that you’ll probably find extremely useful if only you knew they were there in the first place.For instance if you go to the Ruby Doc Standard Library right at the top, the only entry under ‘A’ is Abbrev, a one function API that might save some trouble when it comes to text processing.

The single function of the Abbrev library is to “calculate the set of unique abbreviations for a given set of strings”. Put slightly more simply given an array of strings, Abbrev will return a list of unique non-ambiguous prefixes for each string such that no two strings have the same prefix. So given the words ‘fox’ and ‘fig’ the unique abbreviations for ‘fox’ are ‘fo’ and ‘fox’ and for ‘fig’ is ‘fi’ and ‘fig’ with the prefix of ‘f’ being ambiguous and therefore excluded.

Continue reading Rediscovering Ruby: Abbrev...

12th May Cape Town Ruby Brigade

Talk: Capistrano by Nick Coyne
Date: 12th May 2010
Time: 19:00
Venue: Sudoroom, 5th Floor Bandwidth Barn, 125 Buitengracht, Cape Town

RSVP @ Cape Town Ruby Brigade

14th April Cape Town Ruby Brigade

Topic: Testing with Factory Girl, Cucumber and Pickle
Speakers: Jolwyn Pawlyn and Alex Tomkins from Unboxed Consulting

Factory Girl: http://github.com/thoughtbot/factory_girl
Cucumber: http://www.cukes.info
Pickle: http://ianwhite.github.com/pickle/

Date: 14th April 2010
Time: 19:00
Venue: Sudoroom, 5th Floor Bandwidth Barn, 125 Buitengracht St, Cape Town

10th March Cape Town Ruby Brigade Meeting

Topic: Sequel Database API
Date: 10th March
Time: 19:00
Venue: Sudoroom, 5th Floor Bandwidth Barn, 125 Buitengracht, Cape Town

RSVP and more information at 10th March Meeting Page.

Neat Ruby Tricks: take_while and drop_while

Enumerable is the swiss army chainsaw of Ruby, the functionality it provides to classes which include it is probably used countless times a day in your code. So when new features are added to Enumerable it’s probably a good thing to learn them because they have the potential to make your coding a little bit easier. In this edition of Neat Ruby Tricks we’ll look at two new methods that were introduced to Enumerable in 1.8.7: take_while and drop_while.

Continue reading Neat Ruby Tricks: take_while and drop_while...

2010 Cape Town Ruby Brigade Dates

Mark your calendars for the following Cape Town Ruby Brigade meeting dates:

  • 10th March 2010
  • 14th April 2010
  • 12th May 2010
  • 9th June 2010
  • 14th July 2010
  • 11th August 2010
  • 8th September 2010
  • 13th October 2010
  • 10th November 2010

Announcements for each meeting will be made closer to the time via Cape Town Ruby Brigade Mailing List.

Cape Town Ruby Brigade Meeting - 20th January 2009

Topic: Microformats by Andy Volk
Venue: Sudoroom, Bandwidth Barn, 5th Floor 125 Buitengracht, Cape Town
Date: Wednesday, 20th January 2009
Time: 19:00

RSVP @ Cape Town Ruby Brigade Google Group

Rediscovering Ruby: GServer

One of the great aspects in working with Ruby is not just the language itself but the builtin APIs that come with it. In this series of Rediscovering Ruby articles I will be digging through the Core and Standard Ruby APIs looking for those useful gems that are either undiscovered or that have been forgotten over time. First up GServer, a micro-framework allowing you to quickly create servers that can handle multiple client requests.

Continue reading Rediscovering Ruby: GServer...

Languages To Learn For 2010

It’s generally good programming practise to try to learn, or at least become familiar, with a new programming language every year. 2009 was a bit of a washout for me in this regard but in 2008 it was Erlang and although I haven’t had the time to actually produce a project with Erlang I’ve read Joe Armstrong’s Programming Erlang and like the concept and semantics of the language. The syntax though is still a little bit wierd to me, but that apprehension is probably due to my lack of practise in the language.

This year I’ve decided to try my hand at two languages, one relatively very old and one relatively very new. The old language is Scheme, although I’m still up in the air over which implementation to try: Chicken Scheme or PLT Scheme. The new language is Google’s Go programming language.

I might try and post a few articles on either language on this blog during the course of 2010, that is if I manage to learn enough to not look like a complete rank beginner.

Neat Ruby Tricks: Named Parameters with Ruby 1.9

One of the syntax sugar additions to Ruby 1.9 is the new syntax for specifying hashes with symbols as keys. In 1.9 you can now specify the hash on line 1 in the format on line 2.

1 { :manufacturer => 'Lenovo', :model => 'Thinkpad R500' }
2 { manufacturer: 'Lenovo', model: 'Thinkpad R500' }

Now this might not look like much of an improvement but it shines in method calls where we can use ‘naked’ hashes as named parameters. For example in the following code snippet line 1 (Ruby 1.8) is the equivalent to line 2 (Ruby 1.9)

1 get_price( :manufacturer => 'Lenovo', :model => 'Thinkpad R500' )
2 get_price( manufacturer: 'Lenovo', model: 'Thinkpad R500' )

The expression on line 2 using the new syntax is quite a bit neater (in my own opinion) and makes named parameters even easier to read and parse.

There is one caveat to remember with this and that all keys will be converted into symbols.

1 pc_data = { manufacturer: 'Lenovo', model: 'Thinkpad R500' }
2 pc_data[ :manufacturer ] # => 'Lenovo'
3 pc_data[ 'manufacturer' ] # => nil

About Aimred

Aimred is a specialist Ruby and Ruby on Rails development house and consultancy based in Cape Town, South Africa.

We provide Ruby and Ruby on Rails development, consulting and training services to businesses and organisations of all sizes. If you want to find out how we can help you, contact us at info@aimred.com.

Recent Posts

Yearly Archives