Open redgetan opened 12 years ago
it's tricky to find which line the class_eval is called though because if you just search for the regex /class_eval|module_eval/, then it will capture even comment lines that just include those words.
ie. if the before_save code is modified to the one below, then its gonna potentially create problems
def _define_before_model_callback(klass, callback) #:nodoc:
klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
#
# this is a class_eval HACK, might change in the future API release
#
def self.before_#{callback}(*args, &block)
set_callback(:#{callback}, :before, *args, &block)
end
CALLBACK
end
/Users/reg/.rvm/gems/ruby-1.9.3-p125@pry_sbox/gems/activemodel-3.2.3/lib/active_model/callbacks.rb: 109
As you can see below, the # symbol will be interpreted as a comment so valid_expression? would never return true and readline just keeps going
Problem would have been solved if syntax checking is done at the start of
klass.class_eval
line instead ofdef self.before_
as suggested by @banister.