Created
June 17, 2016 16:29
-
-
Save hugolepetit/588cd46895435cfb97127bfe3f6eb556 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fill_in_form(form_name, &block) | |
previous_self = eval "self", block.binding | |
# Break scope barrier to be able to call on previous self context fill_in method | |
form_filler = Class.new do | |
define_method(:initialize) do |form_name| | |
@form_name = form_name | |
end | |
define_method(:method_missing) do |method_name, *args| | |
previous_self.send(:fill_in, "#{@form_name}[#{method_name}]", with: args[0]) | |
end | |
end | |
yield form_filler.new(form_name) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment