lib/elasticonf/loader.rb in elasticonf-1.1.3 vs lib/elasticonf/loader.rb in elasticonf-1.1.4

- old
+ new

@@ -1,17 +1,25 @@ +require 'semantic' + module Elasticonf class Loader < Hashie::Mash def get(key) unless [String, Symbol].include?(key.class) raise ArgumentError, "String or Symbol expected #{key.class} given" end - - hash, items = self, key.split('.') - - while (item = items.shift) - (hash = hash[item.to_sym]) || break - end - hash + ruby_version = Semantic::Version.new(RUBY_VERSION) + + if ruby_version.major == 2 && ruby_version.minor >= 3 + dig *key.split('.') + else + result, items = self.dup, key.split('.') + + while (item = items.shift) + (result = result[item.to_sym]) || break + end + + result + end end end -end \ No newline at end of file +end