Skip to content

Instantly share code, notes, and snippets.

@rgraff
Created October 16, 2013 02:19
Show Gist options
  • Save rgraff/7001656 to your computer and use it in GitHub Desktop.
Save rgraff/7001656 to your computer and use it in GitHub Desktop.
This is an example of how you might use Oj::ScHandler to replicate the :class_object feature of JSON::Ext::Parser
class CustomHashHandler < Oj::ScHandler
attr_accessor :output
class HandlerHash < Hash
def method_missing(method)
return self[method] if key?(method)
super
end
end
def hash_start()
HandlerHash.new
end
def array_start()
[]
end
def add_value(value)
@output = value
end
def hash_set(h, key, value)
h[key.to_sym] = value
end
def array_append(a, value)
a << value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment