Created
April 16, 2009 19:15
-
-
Save henrik/96600 to your computer and use it in GitHub Desktop.
Like OpenStruct but raises for anything not passed into the constructor.
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
# Like OpenStruct but raises for anything not passed into the constructor. | |
# Unlike Struct in that it's built from a hash, and you don't need to define your own class. | |
# | |
# By Henrik Nyh <http://henrik.nyh.se> 2009-04-16. Public domain. | |
require 'ostruct' | |
class ClosedStruct < OpenStruct | |
def method_missing(symbol, *args) | |
raise(NoMethodError, "undefined method `#{symbol}' for #{self}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment