Created
June 1, 2017 14:43
-
-
Save michaelglass/b702603f4d02ffbd16cfc884896e44dd to your computer and use it in GitHub Desktop.
This file contains 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 Value | |
# alias_method is private, wah wah | |
singleton_class.send(:alias_method, :old_new, :new) | |
def self.new(*fields, &block) | |
klass = old_new(*fields, &block) | |
klass.instance_eval do | |
# Rails' as_json function calls `to_hash` internally and falls back to using `instance_variables`. | |
# `instance_variables` returns Value's internal `hash` attribute which we are not interested in. | |
alias_method :to_hash, :to_h | |
end | |
klass | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment