method

[]=

Importance_0
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: NonSymbolAccessDeprecatedHash
  • 1.0.0
  • 1.1.6
  • 1.2.6
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0 (0)
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2
  • 7.1.3.4
  • What's this?
[]=(key, value) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File railties/lib/rails/application.rb, line 622
        def []=(key, value)
          regular_writer(key.to_sym, convert_value(value, for: :assignment))
        end

        private

          def convert_key(key)
            unless key.kind_of?(Symbol)
              ActiveSupport::Deprecation.warn(<<~MESSAGE.squish)
                Accessing hashes returned from config_for by non-symbol keys
                is deprecated and will be removed in Rails 6.1.
                Use symbols for access instead.
              MESSAGE

              key = key.to_sym
            end

            key
          end

          def convert_value(value, options = {}) # :doc:
            if value.is_a? Hash
              if options[:for] == :to_hash
                value.to_hash
              else
                self.class.new(value)
              end
            elsif value.is_a?(Array)
              if options[:for] != :assignment || value.frozen?
                value = value.dup
              end
              value.map! { |e| convert_value(e, options) }
            else
              value
            end
          end
      end
  end
Register or log in to add new notes.