diff --git a/lib/roda/plugins/_symbol_class_matchers.rb b/lib/roda/plugins/_symbol_class_matchers.rb index 5180adce..59e30201 100644 --- a/lib/roda/plugins/_symbol_class_matchers.rb +++ b/lib/roda/plugins/_symbol_class_matchers.rb @@ -92,7 +92,11 @@ def _merge_matcher_blocks(type, obj, block, matcher_meth) proc do |*a| if captures = send(matcher_meth, *a) - send(convert_meth, *captures) + if captures.is_a?(Array) + send(convert_meth, *captures) + else + send(convert_meth, captures) + end end end else diff --git a/spec/plugin/class_matchers_spec.rb b/spec/plugin/class_matchers_spec.rb index 6e660824..ae6046c7 100644 --- a/spec/plugin/class_matchers_spec.rb +++ b/spec/plugin/class_matchers_spec.rb @@ -152,6 +152,17 @@ def klass9.to_s; "klass9" end body("/1000000000000000000001").must_equal "" end + it "yields hash instances as single arguments" do + app(:class_matchers) do |r| + r.is('a', Array){|h| h.to_a.join(',')} + r.is('h', Hash){|h| h.to_a.join('-')} + end + app.class_matcher(Hash, /(\w)(\w)/){|k,v| {k=>v}} + app.class_matcher(Array, Hash){|h| h['c'] = 'd'; h } + body('/h/ab').must_equal 'a-b' + body('/a/ab').must_equal 'a,b,c,d' + end + it "freezes :class_matchers option when freezing app" do app(:class_matchers){|r| } app.freeze