naught
naught copied to clipboard
Support for NullProxy
As requested in Issue #6.
I'm completely open to name changes. I just picked some reasonable names to start with.
It doesn't mention it in Issue #6 but we need some way to get the actual result or __object__
. I'm not thrilled with this name but I also didn't want to pick something that might exist on the wrapped object. Could go with something like __value__
as well.
I also gave it the option to accept a specific type of null object for the default.
Usage:
require 'naught'
NullProxy([]).first.address.country.__object__ # => <null>
NullProxy([1]).first.abs.__object__ # => 1
null = Naught.build do |config|
config.define_explicit_conversions
end
NullProxy([], null).first.abs.__object__.to_i # => 0
Thanks Alex! I'll review this when I can.