lib/tokenizers/base.rb in twitter_cldr-1.0.0 vs lib/tokenizers/base.rb in twitter_cldr-1.0.1

- old
+ new

@@ -1,5 +1,7 @@ +# encoding: UTF-8 + module TwitterCldr module Tokenizers class Base attr_reader :resource, :locale attr_reader :token_splitter_regex, :token_type_regexes, :paths @@ -48,15 +50,17 @@ def init_placeholders @placeholders = {} end def traverse(needle, haystack = @resource) - segments = needle.to_s.split(".") - final = haystack - segments.each { |segment| final = final[segment.to_sym] } - final - rescue NameError - nil + needle.to_s.split('.').inject(haystack) do |current, segment| + key = segment.to_sym + if current.is_a?(Hash) && current.has_key?(key) + current[key] + else + return + end + end end def expand_pattern(format_str, type) if format_str.is_a?(Symbol) # symbols mean another path was given \ No newline at end of file