Last active
December 17, 2015 16:30
-
-
Save asaaki/8d3b8f58b5e430c1dc9f to your computer and use it in GitHub Desktop.
Null Object Pattern using OpenStruct for simple predefined null objects (PreStep before Monads)
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
# How To Guard Against Ruby Nil Errors | |
# http://www.littlelines.com/blog/2013/06/22/how-to-guard-against-ruby-nil-errors/ | |
# Null Object Pattern | |
# using OpenStruct for simple predefined null objects | |
require "ostruct" | |
NullUser = OpenStruct.new(id: -1, name: "Null User") # ... and additional accessors |
Very good generalized approach/gem: https://github.com/tomstuart/monads
(Ref: Talk at eurucamp 2014 -> http://2014.eurucamp.org/speakers/#tom-stuart)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another article: http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/