Showing posts with label Papers. Show all posts
Showing posts with label Papers. Show all posts

Friday, June 13, 2008

Creating Alternate Ruby Objects

One of the things I've found slightly frustrating about Ruby is the new method. Nearly twenty years ago I was writing code in Objective-C on NeXT, which had explicit allocation and initialization:
   Object foo = [[Foo alloc] init]
Using this invocation, foo could be any sort of Object, and init could return any sort of Object. Ruby (and most other OO languages, for that matter) combine the alloc-init into a 'new' method:
   foo = Foo.new
The problem is that the object returned is a Foo, at least unless a class supplied its own specialized new.

In a short paper I've written, Creating Alternate Ruby Objects, I discuss a generalized mechanism that allows object remapping in new. This enables a class' new method to return a different object than the one allocated, according to decisions made in the initialize method.

The mechanism has been added to the release 1.0.4 of my eymiha rubygem in my Chunks of Ruby Infrastructure Project on RubyForge.

Thursday, May 29, 2008

Easy Logging For Ruby

In the spirit of invisible infrastructure, I built some framework around the Ruby Logger class and made it more succinct, more ubiquitous, and easier to use. The results are discussed in Easy Logging For Ruby, a paper describing the motivation and code that allows a developer to add logging to Ruby code with virtually no effort.

The code is available Chunks of Ruby Infrastructure project as part of the eymiha_util-1.0.1 (or later) rubygem.

Thursday, March 06, 2008

The Units Pipe Dream...

Much of what's driven my off-off-hours development over the last year is the architecture, design and coding of a Units Framework for Ruby. While there are a few out there, this one is different - predicated on a NumericWithUnits, units are added to Numerics transparently. They act exactly like Numerics without units, but assert their types when appropriate and handle conversions automatically, such as:

puts 5.inches + 3.feet->41 inches
puts 55.miles_per_hour.feet_second->80.666666667 ft / s
puts seconds_per_week->604800

To use them you just include the framework and everything just works. Go grab them for free at my CORI (Chunks of Ruby Infrastructure) rubyforge page: http://rubyforge.org/projects/cori/.

I wrote about the development as I went along, and humble submit it for your reading pleasure at http://www.geocities.com/eymiha/papers/TheUnitsPipeDreamV1.html.

This is just the first part of the development, however - only scalar units. I am going to add formulaic conversions (like temperature) and data-driven conversions (like currency) in the next go-round. Coming soon.

Wednesday, May 16, 2007

Handling Forward Reference in Ruby

While doing some DSL work, I found myself with forward referencing problems. I needed to be able to create structures that used information that wasn't yet available. I took a step back and designed a forward reference capture and resolution framework that let me keep my DSL work clean and didn't choke when things are used before they're defined.

I wrote a description of the system and uploaded the code to rubyforge as part of the 0.1.1 release of my eymiha_util rubygem - you can get the paper or download the system from my "chunks of ruby infrastructure" project.

Thursday, April 05, 2007

Gem_raker - A Rake-based Rubygem for Developing Rubygems

While turning some of my old C, C++ and Java library code into Rubygems, I found I was creating an unmanageable mess... changes kept propagating and I needed an easy way to automate testing and installing my locally developed gems. The result is gem_raker, a clean rake-based assembly line for gems.

You can take a look at a description of the system or download it and see if it does what you need.

Tuesday, September 19, 2006

Establishing Session Context

I'm a big fan of context sensitivity. I'm also a big fan of Rails. Recently the two topics crossed paths in the guise of contextual overlap in the session of a large Rails application I've been building, and I decided to get rid of the headache. I've built some code to establish disjoint contexts in the session, transparent to normal Rails development.

Feel free to take a look and comment...

Tuesday, January 24, 2006

Getting DRYer Through Metaprogramming

Recently I did some metaprogramming. I was faced with some soggy Ruby code I'd evolved, and wanted to evaporate some of the moisture. By using metaprogramming, I was able to DRY things out again. Click the link to read a short description of my exploits.

Sunday, November 06, 2005

Going From Java To Ruby

As I began learning Ruby, I started porting some of the simpler objects in my toolbox. I wrote a short paper about the effort made to transition two of these objects, Duration and Stopwatch, as well as a plea for Java developers to start learning Ruby.