lib/builder/xmlbase.rb in builder-3.0.4 vs lib/builder/xmlbase.rb in builder-3.1.0
- old
+ new
@@ -42,12 +42,10 @@
args.each do |arg|
case arg
when ::Hash
attrs ||= {}
attrs.merge!(arg)
- when nil
- # do nothing
else
text ||= ''
text << arg.to_s
end
end
@@ -128,13 +126,11 @@
require 'builder/xchar'
if ::String.method_defined?(:encode)
def _escape(text)
result = XChar.encode(text)
begin
- encoding = ::Encoding::find(@encoding)
- raise Exception if encoding.dummy?
- result.encode(encoding)
+ result.encode(@encoding)
rescue
# if the encoding can't be supported, use numeric character references
result.
gsub(/[^\u0000-\u007F]/) {|c| "&##{c.ord};"}.
force_encoding('ascii')
@@ -177,14 +173,14 @@
# documents are usually very repetative in nature, the next node will
# 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)
+ instance_eval <<-NEW_METHOD
+ def #{sym.to_s}(*args, &block)
+ tag!(:#{sym.to_s}, *args, &block)
end
- end
+ NEW_METHOD
end
end
XmlBase.cache_method_calls = true