module Hexable
  def self.included(base)
    base.class_eval do
      before_create :generate_hex
      attr_accessible :hex
    end
  end

  def to_param
    self.hex
  end

  private

  def generate_hex
    self.hex = SecureRandom.hex
  end
end