Created
December 11, 2014 00:22
-
-
Save dorkrawk/c86621e1f76209dc1f9e to your computer and use it in GitHub Desktop.
A monkeypatch to Ruby Struct to get rid of "warning: redefining constant Struct::whatever" when using Structs
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 Struct | |
def self.new_singleton(name, *fields) | |
if Struct::const_defined?(name) | |
Struct.const_get(name) | |
else | |
Struct.new(name, *fields) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So @dorkrawk - assuming I'm getting this in a rails project, do I put the singleton_struct.rb in my app/models?