Skip to content

Commit 4b65ca6

Browse files
authored
Added alias to_h for to_hash (#277)
1 parent b868f89 commit 4b65ca6

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Bug fixes
6+
7+
* Added alias to_h for to_hash ([#277](https://github.com/railsconfig/config/issues/277))
8+
59
### Changes
610

711
* Add JRuby 9.2 to the test matrix ([#228](https://github.com/railsconfig/config/issues/228))

lib/config/options.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def to_hash
118118
result
119119
end
120120

121+
alias :to_h :to_hash
122+
121123
def each(*args, &block)
122124
marshal_dump.each(*args, &block)
123125
end

spec/config_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@
8080
expect(config[:section][:servers][1]).to be_kind_of(Config::Options)
8181
end
8282

83+
it "should convert to a hash without modifying nested settings" do
84+
config = Config.load_files("#{fixture_path}/development.yml")
85+
config.to_h
86+
expect(config).to be_kind_of(Config::Options)
87+
expect(config[:section]).to be_kind_of(Config::Options)
88+
expect(config[:section][:servers][0]).to be_kind_of(Config::Options)
89+
expect(config[:section][:servers][1]).to be_kind_of(Config::Options)
90+
end
91+
8392
it "should convert to a json" do
8493
config = Config.load_files("#{fixture_path}/development.yml").to_json
8594
expect(JSON.parse(config)["section"]["servers"]).to be_kind_of(Array)

0 commit comments

Comments
 (0)