Last active
August 29, 2015 14:07
-
-
Save Neener54/fc98611e5b64bbd41712 to your computer and use it in GitHub Desktop.
Simple Null Object Pattern
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
class NullObject | |
# You can instantiate a new NullObject with arbitrary methods by calling | |
# NullObject.new({method1: "outcome1"}) | |
# That will apply the method to the object | |
def initialize(methods={}) | |
methods.each_pair do |k,v| | |
define_singleton_method k do |*params| | |
v | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Say you need something that quacks like current_user.has_a_pony.
You can just do: