I'm in love with IronRuby
I’ve been playing with IronRuby a lot lately, and it’s turning out to be every bit as amazing as I’d hoped it would be. I’m constantly thinking about new stuff to do with it, but one of the easiest low hanging fruits is rewriting our existing unit tests in ruby.
I’ve been putting together a little library of IronRuby specific modules for tests. You’ve got to love being able to do things like this:
class Class
def should_implement(interface)
!to_clr_type.nil? && !to_clr_type.get_interface(interface).nil?
end
end
>>> MyClass.should_implement "ISomething"
=> trueBringing the power of Ruby to .NET is going to be incredible. It feels great clicking both the Ruby and .NET tags on a post. More on this to come…
Javascript Gotchas Are Fun!
And by fun I mean "will make you bang your head against the wall repeatedly."
Explanation here: http://www.jibbering.com/faq/#FAQ4_7
This Is Why Dreamhost Sucks
[eggnog]$ time ./dispatch.fcgi real 2m48.176s user 0m2.090s sys 0m0.550s
And they want me to renew my hosting tomorrow.
Playing Nice with Legacy Data
I was working with a database that had its own rules for pluralization and I wrote a quick hack to try to get ActiveRecord to play nice with their naming conventions. It still crashes and burns a lot, but it’s a work in progress.
module Inflector
def pluralize(word)
if ( word[-1..-1].downcase == 's' ||
word[-1..-2].downcase == 'sh' ||
word[-1..-2].downcase == 'ch' ||
word[-1..-1].downcase == 'x'
)
word << 'es'
elsif word[-1..-1].downcase == 'y'
if ['a', 'e', 'i', 'o', 'u'].include? word[-2..-2]
word << 's'
else
word = word[0..word.length-2] << 'ies'
end
else
word << 's'
end
end
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
class_name
end
end
class ActiveRecord::Base
class << self
def reset_primary_key #:nodoc:
key = "#{base_class.name}ID"
set_primary_key(key)
key
end
private
def undecorated_table_name(class_name = base_class.name)
table_name = Inflector.pluralize(class_name)
puts table_name
table_name
end
end
end
It still needs a lot of work, but I think it will be pretty cool to get active record to make correct assumptions about table names and keys without explicitly defining them.
Because it's better than text files
So I finally caved and made a blog. I found myself saving code snippets of cool things that I’d picked up in text files on whatever machine I happened to be working on. This brought on a few problems.
First, I am extremely unorganized, and would forget about (and soon after lose forever) the text file containing whatever gem of knowledge I had come across.
Second, a text file saved at work doesn’t help me much at home.
Third (theoretically) someone else out there might have some bizzare desire to read the contents of whatever text file I was in the process of losing.
Thus, this blog was born. I doubt anyone will ever read this, but if it does somehow end up serving a greater good than my personal online sticky note, all the better. Enjoy.