Skip to content

Commit

Permalink
Check the keys of the criteria just once
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Apr 6, 2011
1 parent 4cbf320 commit 3bb95c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/mechanize/form.rb
Expand Up @@ -346,9 +346,14 @@ def delete_field!(field_name)
eval(<<-eomethod)
def #{plural}_with criteria = {}
criteria = {:name => criteria} if String === criteria
criteria = criteria.map do |k, v|
k = :dom_id if k.to_sym == :id
[k, v]
end
f = #{plural}.find_all do |thing|
criteria.all? do |k,v|
k = :dom_id if(k.to_s == "id")
v === thing.send(k)
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/mechanize/page.rb
Expand Up @@ -196,9 +196,14 @@ def content_type
eval(<<-eomethod)
def #{type}s_with(criteria)
criteria = {:name => criteria} if String === criteria
criteria = criteria.map do |k, v|
k = :dom_id if k.to_sym == :id
[k, v]
end
f = #{type}s.find_all do |thing|
criteria.all? do |k,v|
k = :dom_id if(k.to_s == "id")
v === thing.send(k)
end
end
Expand Down

0 comments on commit 3bb95c2

Please sign in to comment.