Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created February 25, 2012 16:51
Show Gist options
  • Save workmad3/1909487 to your computer and use it in GitHub Desktop.
Save workmad3/1909487 to your computer and use it in GitHub Desktop.
class DefaultOpenStruct < BasicObject
def initialize(hash, default = nil)
@struct = OpenStruct.new(hash)
@default = default
end
def method_missing(*args, &blk)
@struct.send(*args, &blk) || @default
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment