Fix duplicate constant definitions for Ruby 1.8

Ruby 1.8.7 does not like the `||=` construction for Class constants,
so use `defined?` to check if the constants are already declared.

Fixes #169.