Ruby has Integer(...) and Float(...), but does it have Boolean(…) for things like:

Boolean(ENV[“SOME_FLAG”])

What's the Ruby idiom here?

@getajobmike for env vars in particular, !ENV.fetch("MIKE_IS_RAD", "").empty? but that's gross and isn't general enough for a Boolean(...)

@jc00ke @getajobmike Since ENV isn't a hash, it could theoretically specialize on string formats like this, letting it return numbers or booleans.

FLAG=true SIDEKIQ_WORKERS=5

ENV.boolean("FLAG") # => true
ENV.boolean("UNSET_FLAG") # => nil
ENV.integer("SIDEKIQ_WORKERS") # => 5

https://gist.github.com/jgaskins/de1f724e980ce29e31ac90eb2b5bab1f

Type coercion for ENV

Type coercion for ENV. GitHub Gist: instantly share code, notes, and snippets.

Gist
@jamie @getajobmike ooh I like that.