Skip to content

Instantly share code, notes, and snippets.

@taylor
Created September 23, 2011 15:31
Show Gist options
  • Select an option

  • Save taylor/1237667 to your computer and use it in GitHub Desktop.

Select an option

Save taylor/1237667 to your computer and use it in GitHub Desktop.
def self.new(element_name, atts = {}, &block)
blk_proc = Proc.new do |new_node|
atts.each_pair { |k, v| new_node.send :"#{k}=", v }
block_return = new_node.instance_eval &block if block_given?
new_node << new_node.encode_special_chars(block_return) if block_return.is_a?(String)
end
case RUBY_VERSION.split(/\./)[0,2].join.to_i
when 18
super(element_name).tap do |n|
blk_proc[n]
end
else
super(element_name) do |n|
blk_proc[n]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment