lib/object_extra.rb
# Predefined entities in XML for ruby 1.8.7.
#  Simulate *part* of the functionality of ruby >= 1.9.1:
# - s.encode(:xml => :text)
# - s.encode(:xml => :attr)
Predefined entities in XML for ruby 1.8.7.
Predefined entities in XML for ruby 1 . 8 . 7 .
def encode2(opts={})
    xml_entity_lookup = [
      [/&/, "&amp;"],
      [/</, "&lt;"],
      [/>/, "&gt;"],
    ]
    if opts[:xml] == :text
      xml_entity_lookup.inject(self){|s,(regex, subst)| s.gsub(regex, subst)}
    elsif opts[:xml] == :attr
      xml_entity_lookup << [/"/, "&quot;"]
      xml_entity_lookup.inject(self){|s,(regex, subst)| s.gsub(regex, subst)}
    else
      self
    end
  end
def encode2 ( opts = { } ) xml_entity_lookup = [ [ / & / , "&amp;" ] , [ / < / , "&lt;" ] , [ / > / , "&gt;" ] , ] if opts [ :xml ] == :text xml_entity_lookup . inject ( self ) { | s , ( regex , subst ) | s . gsub ( regex , subst ) } elsif opts [ :xml ] == :attr xml_entity_lookup << [ / " / , "&quot;" ] xml_entity_lookup . inject ( self ) { | s , ( regex , subst ) | s . gsub ( regex , subst ) } else self end end
Predefined entities in XML for ruby 1.8.7.
Predefined entities in XML for ruby 1 . 8 . 7 .
opts
<not_specific>