1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #44644 from tonobo/active_support_inheritable_options_add_dig

ActiveSupport::OrderedOptions handle custom #dig
This commit is contained in:
Aaron Patterson 2022-03-09 10:48:12 -08:00 committed by GitHub
commit 44e5a31d85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -40,6 +40,10 @@ module ActiveSupport
super(key.to_sym)
end
def dig(*keys)
super(*keys.flatten.map(&:to_sym))
end
def method_missing(name, *args)
name_string = +name.to_s
if name_string.chomp!("=")

View file

@ -36,6 +36,16 @@ class OrderedOptionsTest < ActiveSupport::TestCase
end
end
def test_string_dig
a = ActiveSupport::OrderedOptions.new
a[:test_key] = 56
assert_equal 56, a.test_key
assert_equal 56, a['test_key']
assert_equal 56, a.dig(:test_key)
assert_equal 56, a.dig('test_key')
end
def test_method_access
a = ActiveSupport::OrderedOptions.new