Removed lazy way of setting instance variables.

This process is quite a bit slower compared to setting instance variables
directly.
This commit is contained in:
Yorick Peterse 2014-05-15 00:43:13 +02:00
parent 043ea9a366
commit f4b9bbd4ac
6 changed files with 39 additions and 23 deletions

View File

@ -38,9 +38,11 @@ module Oga
# @option options [String] :system_id
#
def initialize(options = {})
options.each do |key, value|
instance_variable_set("@#{key}", value) if respond_to?(key)
end
@name = options[:name]
@type = options[:type]
@public_id = options[:public_id]
@system_id = options[:system_id]
@inline_rules = options[:inline_rules]
end
##

View File

@ -27,11 +27,9 @@ module Oga
# @option options [Oga::XML::XmlDeclaration] :xml_declaration
#
def initialize(options = {})
options.each do |key, value|
instance_variable_set("@#{key}", value) if respond_to?(key)
end
@children ||= []
@children = options[:children] || []
@doctype = options[:doctype]
@xml_declaration = options[:xml_declaration]
end
##

View File

@ -19,8 +19,19 @@ module Oga
class Element < Node
attr_accessor :name, :namespace, :attributes
def after_initialize
@attributes ||= {}
##
# @param [Hash] options
#
# @option options [String] :name The name of the element.
# @option options [String] :namespace The namespace of the element.
# @option options [Hash] :attributes The attributes of the element.
#
def initialize(options = {})
super
@name = options[:name]
@namespace = options[:namespace]
@attributes = options[:attributes] || {}
end
##

View File

@ -30,13 +30,10 @@ module Oga
# @option options [Oga::XML::Node] :previous The previous node.
#
def initialize(options = {})
options.each do |key, value|
instance_variable_set("@#{key}", value) if respond_to?(key)
end
@children ||= []
after_initialize if respond_to?(:after_initialize)
@parent = options[:parent]
@children = options[:children] || []
@next = options[:next]
@previous = options[:previous]
end
##

View File

@ -10,6 +10,17 @@ module Oga
class Text < Node
attr_accessor :text
##
# @param [Hash] options
#
# @option options [String] :text The text of the node.
#
def initialize(options = {})
super
@text = options[:text]
end
##
# @return [String]
#

View File

@ -26,12 +26,9 @@ module Oga
# @option options [String] :standalone
#
def initialize(options = {})
options.each do |key, value|
instance_variable_set("@#{key}", value) if respond_to?(key)
end
@version ||= '1.0'
@encoding ||= 'UTF-8'
@version = options[:version] || '1.0'
@encoding = options[:encoding] || 'UTF-8'
@standalone = options[:standalone]
end
##