On Tue, 20 Jul 2004 01:07:07 +0900, Robert Klemme <bob.news / gmx.net> wrote:
> 
> "Edgardo Hames" <ehames / gmail.com> schrieb im Newsbeitrag
> news:478c16ae04071907072c000169 / mail.gmail.com...
> 
> > Hi, everybody. I wondered how would you write a ResourceBundle-like
> > class in Ruby. Basically, what I need is hash which is initialized by
> > reading key,value pairs from a file.
>
> I'm not 100% sure at the moment, but the lookup
> is two level, isn't it?  I mean, you select a bundle via Locale and then
> do the lookup along the Locale "hierarchy".  So you probably need some
> parent member along these lines:
> 
> class ResourceBundle < Hash
>  attr_accessor :parent
> 
>  def initialize(fileName)
>    File.open(fileName) do |io|
>      io.each do |line|
>        /^\s*(\S+)\s*[=:]\s*(.*)$/ =~ line and self[$1]= $2
>      end
>    end
>  end
> 
>  def [](key)
>    result = super
>    result = parent[key] if result.nil? && parent
>    result
>  end
> 
> end

I don't understand the parent member. Is it the fall back bundle it is
used in case the program doesn't found the localized one? When is it
filled up with data?

Regards,
Ed