Use define_singleton_method insted of class << self and define_method.