instance method option

Ruby on Rails edge

Since edge

Signature

option(*key, default: nil)

Find an upcased and double-underscored-joined string-version of the key in ENV. Returns nil if the key isn’t found. If a default value is defined, it (or its callable value) will be returned on a missing key.

Given ENV:

DB_HOST: "env.example.com"
DATABASE__HOST: "env.example.com"

Examples:

option(:db_host)                              # => "env.example.com"
option(:missing)                              # => nil
option(:missing, default: "localhost")        # => "localhost"
option(:missing, default: -> { "localhost" }) # => "localhost"

Parameters

key rest
default key = nil
Source
# File activesupport/lib/active_support/env_configuration.rb, line 65
    def option(*key, default: nil)
      if default.respond_to?(:call)
        @envs.fetch(envify(*key)) { default.call }
      else
        @envs.fetch envify(*key), default
      end
    end

Defined in activesupport/lib/active_support/env_configuration.rb line 65 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::EnvConfiguration

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close