naught icon indicating copy to clipboard operation
naught copied to clipboard

Support for NullProxy

Open alexpeachey opened this issue 10 years ago • 1 comments

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 , otherwise all you have is the proxy. I chose to go with a method called __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

alexpeachey avatar Jul 28 '14 00:07 alexpeachey

Thanks Alex! I'll review this when I can.

avdi avatar Jul 29 '14 01:07 avdi