Skip to content

Commit 1a63f94

Browse files
[Documentation] ActiveSupport::InheritableOptions with string keys
Updated the ActiveSupport::InheritableOptions documentation to exemplify how to use a parent hash that contains string keys. parent = { "foo" => true } child = ActiveSupport::InheritableOptions.new(parent.symbolize_keys) child.foo # => true This example is helpful because ActiveSupport::OrderedOptions only deals with symbol keys and this implementation detail is hidden from the API docs. Co-authored-by: Jonathan Hefner <[email protected]>
1 parent 8d56a0e commit 1a63f94

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

activesupport/lib/active_support/ordered_options.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def inspect
8484
# h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
8585
# h.girl # => 'Mary'
8686
# h.boy # => 'John'
87+
#
88+
# If the existing hash has string keys, call Hash#symbolize_keys on it.
89+
#
90+
# h = ActiveSupport::InheritableOptions.new({ 'girl' => 'Mary', 'boy' => 'John' }.symbolize_keys)
91+
# h.girl # => 'Mary'
92+
# h.boy # => 'John'
8793
class InheritableOptions < OrderedOptions
8894
def initialize(parent = nil)
8995
if parent.kind_of?(OrderedOptions)

0 commit comments

Comments
 (0)