Skip to content

Instantly share code, notes, and snippets.

@henrik
Created April 16, 2009 19:15
Show Gist options
  • Save henrik/96600 to your computer and use it in GitHub Desktop.
Save henrik/96600 to your computer and use it in GitHub Desktop.
Like OpenStruct but raises for anything not passed into the constructor.
# 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