Created
October 16, 2013 02:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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