Skip to content

Replace string eval

gitlab-qa-bot requested to merge github/fork/cupakromer/replace-string-eval into master

Created by: cupakromer

First pass at replacing all uses of string eval per https://github.com/rspec/rspec-mocks/issues/267

I've tested on 1.8.7-p374, 1.9.3-p392, and 2.0.0-p247.

One potential issue is that I made the decision to use Module#class_exec which was only added in 1.8.7 and 1.9. I did this for two reasons:

  1. It only supports blocks (not possible to pass strings)
  2. It provides the ability to directly pass instance variables into the evaluation block, instead of having to exploit the block closure with local variables:
# Using class_exec
@klass.class_exec(@method_name) do |method_name|
  define_method(method_name) do
    # ...
  end
end

# Using class_eval
method_name = @method_name
@klass.class_eval do
  define_method(method_name) do
    # ...
  end
end

This will break 1.8.6 support. Let me know what you think.

Merge request reports