diff --git a/README.md b/README.md index b1fdaf7..ffbf040 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,10 @@ module Jsonifier alias_visit_method :serialize + def_serialize String do |object| + '"' + object.to_s + '"' + end + # […] end diff --git a/lib/eavi/visitor.rb b/lib/eavi/visitor.rb index 416c5e8..f9ba254 100644 --- a/lib/eavi/visitor.rb +++ b/lib/eavi/visitor.rb @@ -103,6 +103,8 @@ module MethodsWhenIncluded def specialized_alias_visit_method(visit_method_alias) define_method(visit_method_alias, instance_method(:visit)) + define_singleton_method(('def_' + visit_method_alias.to_s).to_sym, method(:def_visit)) + define_singleton_method(('undef_' + visit_method_alias.to_s).to_sym, method(:undef_visit)) end def specialized_add_visit_method(type, block) @@ -130,6 +132,8 @@ module MethodsWhenExtended def specialized_alias_visit_method(visit_method_alias) define_singleton_method(visit_method_alias, method(:visit)) + define_singleton_method(('def_' + visit_method_alias.to_s).to_sym, method(:def_visit)) + define_singleton_method(('undef_' + visit_method_alias.to_s).to_sym, method(:undef_visit)) end def specialized_add_visit_method(type, block) diff --git a/test/visitor_test.rb b/test/visitor_test.rb index de6ae5e..4951d89 100644 --- a/test/visitor_test.rb +++ b/test/visitor_test.rb @@ -135,13 +135,11 @@ it do Reader.class_eval do alias_visit_method :read - - def_visit Page do - # [...] - end end assert_respond_to @reader, :read + assert_respond_to Reader, :def_read + assert_respond_to Reader, :undef_read end end @@ -350,13 +348,11 @@ it do Printer.class_eval do alias_visit_method :print - - def_visit Page do - # [...] - end end assert_respond_to Printer, :print + assert_respond_to Printer, :def_print + assert_respond_to Printer, :undef_print end end