Sha256: ae0e9c92675897d2e94b7e80eed50172aba7410dc5719d3012fb5935f3955c49

Contents?: true

Size: 504 Bytes

Versions: 2

Compression:

Stored size: 504 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
    end
    
    # output nice inspect syntax
    def to_s
      to_h.inspect
    end
    
    alias inspect to_s
    
    def to_query
      to_h.to_query
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cannikin-gattica-0.1.4 lib/gattica/convertible.rb
cannikin-gattica-0.2.0 lib/gattica/convertible.rb