Saturday 15 August 2015

ruby - Removing the class name from Nokogiri::XML::Node::SaveOptions constants -


Do anyhow include in the same manner as a constant I have a module?

I am currently using

  save_options = Nokogiri :: XML :: Node :: SaveOptions :: FORMAT | Nokogiri :: XML :: Node :: SaveOptions :: AS_HTML says html.serialize (: save_with = & gt; save_options)   

is more

 < Code> Html.serialize (: save_with = & gt; FORMAT | AS_HTML)   

I can do a bit by using it.

  nokia: XML includes serialize (serialize: save_with = & gt; node :: save option :: format :: node :: save option :: AS_HTML)  

or

 < Code> html.serialize (: Save_with = & gt; Notchory :: XML :: Node :: SaveOnNew format.ASHHML)   

but none of them are ideal Is there. Anyone have a better way? I do not see any reason that it can not be a module rather than a class, because the benefits of creating an object do not exist.

The safest thing to do will be to do "hand-by-constants" if you need it If you type in the radius, then the constant will be defined with the correct value:

  class YourClass # or module% Module% w (FORMAT AS_HTML) .each do | Konst Const_set (konst, nokogiri :: XML :: Node :: saveOptions.const_get (konst)) End of End   

If the number of constants is large, then you can automate the creation a bit . The problem is that it is not everything or nothing, and things like the class name are also stable, so they will also be imported. This is not a problem for the constants looking for you.

  Category YourClass Nokogiri :: XML :: Node :: saveOptions.constants.each do | Konst   

Hope this helps.

No comments:

Post a Comment