From f36767ad7f5149d0543294b7686823fc8b704afc Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Thu, 17 Jun 2021 11:27:34 +0900 Subject: [PATCH] refactor macro --- src/mechanize/form.cr | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/mechanize/form.cr b/src/mechanize/form.cr index dc01c53..7a9092f 100644 --- a/src/mechanize/form.cr +++ b/src/mechanize/form.cr @@ -41,19 +41,7 @@ class MechanizeCr::Form {% for singular, index in ["field", "radiobutton"] %} {% plural = "#{singular.id}s" %} def {{plural.id}}_with(criteria) - value = Hash(String,String).new - if String === criteria - value = {"name" => criteria} - else - # TODO - # when args whose type isn't String is given - end - f = {{plural.id}}.select do |elm| - value.all? do |k,v| - v === elm.name - end - end - f.empty? ? nil : f + {{plural.id}}_with(criteria){} end def {{plural.id}}_with(criteria, &block) @@ -69,6 +57,7 @@ class MechanizeCr::Form v === elm.name end end + return nil if f.empty? yield f f end