lib/builder/xmlbase.rb in builder-3.1.4 vs lib/builder/xmlbase.rb in builder-3.2.0
- old
+ new
@@ -29,10 +29,14 @@
@indent = indent
@level = initial
@encoding = encoding.downcase
end
+ def explicit_nil_handling?
+ @explicit_nil_handling
+ end
+
# Create a tag named +sym+. Other than the first argument which
# is the tag name, the arguments are the same as the tags
# implemented via <tt>method_missing</tt>.
def tag!(sym, *args, &block)
text = nil
@@ -43,11 +47,12 @@
case arg
when ::Hash
attrs ||= {}
attrs.merge!(arg)
when nil
- # do nothing
+ attrs ||= {}
+ attrs.merge!({:nil => true}) if explicit_nil_handling?
else
text ||= ''
text << arg.to_s
end
end
@@ -178,11 +183,13 @@
# be handled by the new method instead of method_missing. As
# method_missing is very slow, this speeds up document generation
# significantly.
def cache_method_call(sym)
class << self; self; end.class_eval do
- define_method(sym) do |*args, &block|
- tag!(sym, *args, &block)
+ unless method_defined?(sym)
+ define_method(sym) do |*args, &block|
+ tag!(sym, *args, &block)
+ end
end
end
end
end