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:
commit
44e5a31d85
2 changed files with 14 additions and 0 deletions
|
@ -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!("=")
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue