Skip to content

Commit 44e5a31

Browse files
authored
Merge pull request rails#44644 from tonobo/active_support_inheritable_options_add_dig
ActiveSupport::OrderedOptions handle custom #dig
2 parents fa50f7c + 5c15b58 commit 44e5a31

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

activesupport/lib/active_support/ordered_options.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def [](key)
4040
super(key.to_sym)
4141
end
4242

43+
def dig(*keys)
44+
super(*keys.flatten.map(&:to_sym))
45+
end
46+
4347
def method_missing(name, *args)
4448
name_string = +name.to_s
4549
if name_string.chomp!("=")

activesupport/test/ordered_options_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ def test_looping
3636
end
3737
end
3838

39+
def test_string_dig
40+
a = ActiveSupport::OrderedOptions.new
41+
42+
a[:test_key] = 56
43+
assert_equal 56, a.test_key
44+
assert_equal 56, a['test_key']
45+
assert_equal 56, a.dig(:test_key)
46+
assert_equal 56, a.dig('test_key')
47+
end
48+
3949
def test_method_access
4050
a = ActiveSupport::OrderedOptions.new
4151

0 commit comments

Comments
 (0)