Skip to content

Instantly share code, notes, and snippets.

@hugolepetit
Created June 17, 2016 16:29
Show Gist options
  • Save hugolepetit/588cd46895435cfb97127bfe3f6eb556 to your computer and use it in GitHub Desktop.
Save hugolepetit/588cd46895435cfb97127bfe3f6eb556 to your computer and use it in GitHub Desktop.
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