What's the best way to get pretty, Rubified hash keys?
Ie. someKey
becomes some_key
.
Hashie::Trash -- impossible without first defining each key, ie.
property :some_key, from: :someKey
-- not very pretty.https://github.com/tcocca/rash -- unfortunately breaks Hashie::Extensions::DeepFetch which I intend to use later on.
Rails ActiveSupport's
underscore
-- unclear how to apply this to my use case.
Live demo app: http://runnable.com/U-QJCIFvY2RGWL9B/pretty-json-keys
class MainController < ApplicationController
def index
@json_text = <<END
...
END
response = JSON.parse(@json_text)['products']
@products = []
response.each do |product|
@products << product['salePrice']
# Seeking the best way to make this say:
# @products << product['sale_price']
end
end
end