Xml builder, dynamic methods

Is there a way to do something like:

x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
x.instruct!
x.response{
x.XXXXX{

XXXXX is a variable sent in to a method.

Chris H. wrote:

Is there a way to do something like:

x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
x.instruct!
x.response{
x.XXXXX{

XXXXX is a variable sent in to a method.

Can you clarify? I don’t understand your question.

x.XXXXX { … } would create an XML tag named “XXXXX”

<?xml version="1.0"?> ...

Attributes are added by passing in a hash x.XXXXX(:title => “foo”, name
=> “bar”) { … }

<?xml version="1.0"?> ...

What are you actually trying to do?

Take success or error in as a text and replace the below with:

if type.eql?(‘success’)
x.success do
x.message “#{msg}”
end
else
x.error do
x.message “#{msg}”
end
end

Final version:
remove the duplication.
type = “success” or “error”
x.type do
x.message “”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs