Created
December 16, 2010 07:27
-
-
Save beccasaurus/743157 to your computer and use it in GitHub Desktop.
fill_in_fields (i keep re-implementing this ...)
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
# Usage: | |
# fill_in_fields :foo => 'bar' # fill_in 'foo', :with => 'bar' | |
# fill_in_fields :user, :name => 'bob' # fill_in 'user_name', :with => 'bob' | |
# fill_in_fields :contact, :address, :street => '6 cedar rd' # fill_in 'contact_address_street_, :with => '6 cedar rd' | |
def fill_in_fields *args | |
field, value = args.pop.first | |
prefix = '' | |
while args.any? | |
prefix += args.shift.to_s + "_" | |
end | |
fill_in "#{prefix}#{field}", :with => value | |
end |
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 a, options | |
puts "fill_in(#{a.inspect}, #{options.inspect})" | |
end | |
>> fill_in_fields :foo => 'bar' | |
fill_in("foo", {:with=>"bar"}) | |
>> fill_in_fields :user, :name => 'bob' | |
fill_in("user_name", {:with=>"bob"}) | |
>> fill_in_fields :contact, :address, :street => '6 cedar rd' | |
fill_in("contact_address_street", {:with=>"6 cedar rd"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment