instance method option

Ruby on Rails edge

Since edge

Signature

option(*key, default: nil)

Find singular or nested keys. 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 or nil value.

Given configuration:

db_port: null
database:
  host: "db.example.com"

Examples:

option(:database, :host)               # => "db.example.com"
option(:missing)                       # => nil
option(:missing, default: "localhost")        # => "localhost"
option(:missing, default: -> { "localhost" }) # => "localhost"
option(:db_port, default: 5432)               # => 5432 (nil values use default)

Parameters

key rest
default key = nil
Source
# File activesupport/lib/active_support/encrypted_configuration.rb, line 114
    def option(*key, default: nil)
      value = dig(*key)

      if !value.nil?
        value
      elsif default.respond_to?(:call)
        default.call
      else
        default
      end
    end

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

Defined in ActiveSupport::EncryptedConfiguration

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