I’d like to return a string only if not nil and not blank (else return nil). Is there anything like that baked into the language or the standard library?
a = nil
a.presence # nil
b = ""
b.presence # nil
c = "abc"
c.presence # "abc"
I’d like to return a string only if not nil and not blank (else return nil). Is there anything like that baked into the language or the standard library?
a = nil
a.presence # nil
b = ""
b.presence # nil
c = "abc"
c.presence # "abc"
https://crystal-lang.org/api/master/String.html#presence:self?-instance-method
It’s currently only in master so will have to wait for the next release.
Thanks! So looking forward to the release.
Could also use a nightly release via Docker, Snap, or build from source until then.