Permalink
Browse files

Avoid unnecessary String object creation for the method comparison

  • Loading branch information...
1 parent 4a2b81c commit 0bb78f796384289cf20e978c7502f5710a472356 @dkubb dkubb committed Aug 9, 2011
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/virtus/coercion/object.rb
@@ -5,6 +5,8 @@ class Coercion
class Object < Coercion
primitive ::Object
+ COERCION_METHOD_REGEXP = /\Ato_/.freeze
+
# Passthrough given value
#
# @param [Object] value
@@ -13,7 +15,7 @@ class Object < Coercion
#
# @api private
def self.method_missing(method, *args)
- if method.to_s[0, 3] == 'to_' && args.size == 1
+ if method.to_s =~ COERCION_METHOD_REGEXP && args.size == 1
args.first
else
super

0 comments on commit 0bb78f7

Please sign in to comment.