Sha256: 67df78d6ed6ea5a0b3d89ec06bd9b09b55317715cc36711e3bea164c6b215d50
Contents?: true
Size: 782 Bytes
Versions: 5
Compression:
Stored size: 782 Bytes
Contents
module Gattica # Common output methods that are sharable module Convertible # output as hash def to_h output = {} instance_variables.each do |var| output.merge!({ var[1..-1] => instance_variable_get(var) }) unless var == '@xml' # exclude the whole XML dump end output.tap { |h| h.include? HashExtensions } end # output nice inspect syntax def to_s to_h.inspect end alias inspect to_s def to_query to_h.to_query end # Return the raw XML (if the object has a @xml instance variable, otherwise convert the object itself to xml) def to_xml if @xml @xml else self.to_xml end end alias to_yml to_yaml end end
Version data entries
5 entries across 5 versions & 4 rubygems