Method: REXML::Attribute#initialize
- Defined in:
- lib/rexml/attribute.rb
#initialize(first, second = nil, parent = nil) ⇒ Attribute
Constructor. FIXME: The parser doesn’t catch illegal characters in attributes
- first
-
Either: an Attribute, which this new attribute will become a clone of; or a String, which is the name of this attribute
- second
-
If
firstis an Attribute, then this may be an Element, or nil. If nil, then the Element parent of this attribute is the parent of thefirstAttribute. If the first argument is a String, then this must also be a String, and is the content of the attribute. If this is the content, it must be fully normalized (contain no illegal characters). - parent
-
Ignored unless
firstis a String; otherwise, may be the Element parent of this attribute, or nil.
Attribute.new( attribute_to_clone )
Attribute.new( attribute_to_clone, parent_element )
Attribute.new( "attr", "attr_value" )
Attribute.new( "attr", "attr_value", parent_element )
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rexml/attribute.rb', line 44 def initialize( first, second=nil, parent=nil ) @normalized = @unnormalized = @element = nil if first.kind_of? Attribute self.name = first. @unnormalized = first.value if second.kind_of? Element @element = second else @element = first.element end elsif first.kind_of? String @element = parent self.name = first @normalized = second.to_s else raise "illegal argument #{first.class.name} to Attribute constructor" end end |