solnic / coercible

Powerful, flexible and configurable coercion library. And nothing more.
MIT License
137 stars 16 forks source link

Coercer::Object - dynamically define to_* method inside method_missing #22

Open kml opened 8 years ago

kml commented 8 years ago

Benchmark code: https://gist.github.com/kml/0fb1588fc1b6ba4c60fa While testing on JRuby I'm gaining at least x2 improvement thanks to defining method.

Other solution (maybe even better) could be to staticaly define methods like:

module Coercible
  class Coercer
    class Object
      def to_object(value)
        value
      end

      def to_boolean(value)
        value
      end
    end
  end
end