Fix Class#singleton_class? for Ruby 2.1 compatability

This is a backport of https://github.com/rails/rails/pull/12532 to Rails 3.2