Aimred Developer Blog 
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
RCAP 0.3 Released
I’ve just pushed out RCAP 0.3. This is a bugfix release and fixes some issues when parsing from YAML documents.
RCAP 0.2 Released
I’ve just pushed out the RCAP 0.2 gems. This release adds a whole bunch of textual goodness for developers. The main features in this release are
- YAML Support
- inspect/to_s implemented across all RCAP classes
For further information check out the RCAP project page, or you can read some release notes below.
Continue reading RCAP 0.2 Released
Neat Ruby Tricks: File.open Return Values
Back when I started using Ruby I would often read in data from a file as follows
1 file = File.new( 'data.txt' ) 2 parsed_data = parse( file ) 3 file.close
Later I switched to using File.open which handles closing the file for you
1 parsed_data = nil # Required otherwise parsed_data will be nil outside the block 2 File.open( 'data.txt' ) do |file| 3 parsed_data = parse( file ) 4 end
Recently I realised, and felt pretty stupid for not having realised it earlier, that File.open will return the last expression evaluated in it’s block. Which means the above can be rewritten as
1 parsed_data = File.open( 'data.txt' ) do |file| 2 parse( file ) 3 end
or as a much more elegent single line version (and now my preferred method)
1 parsed_data = File.open( 'data.txt' ){ |file| parse( file )}
