cloocher / xmlhasher

Fast XML to Ruby Hash converter
MIT License
40 stars 21 forks source link

Make hash key type configurable #1

Closed charl closed 11 years ago

charl commented 11 years ago

My use case is for a long-running ruby service. As such symbols as keys tend to "leak" memory over time if enough new symbols are seen as the ruby GC does not free these refs.

When hash keys are however strings the GC does not bloat as much over time so it would be very useful for certain use cases to specify the type used (string | symbol) for hash keys instead of defaulting to symbols.

I currently use this monkey patch to modify xmlhasher's behaviour for me:

module XmlHasher
  module Util
    def self.snakecase(str)
      str.to_s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z])([A-Z])/, '\1_\2').downcase.tr('-', '_')
    end
  end
end

This is of course not ideal and support for this in the lib itself makes more sense.

cloocher commented 11 years ago

@charl,

I've added a new configuration option - :string_keys If you set it to 'true', all keys will be Strings instead of Symbols.

Let me know if that works for you.

charl commented 11 years ago

@cloocher works as advertised.

Thanks.