From: Jason Creighton Date: 2003-08-25T09:23:25+09:00 Subject: Re: Wrapping ENV On Fri, 22 Aug 2003 05:03:51 +0900 "Hal E. Fulton" wrote: > I just wrote a little piece of code. Is it useful to anyone but > me? And/or do you see a more elegant way to do it, or any problems > with it? Mentioned in other posts, it assumes that environmental variables are uppercase. No biggie, most of them are. But I can't resist throwing code out, so what about something like this: class WrapHash def initialize(hash) @hash = hash end def method_missing(symbol, *args) str = symbol.id2name setter = str.sub!(/=$/, "") var = [str, str.upcase, str.downcase].detect { |key| @hash.include?(key) } if setter @hash[var] = *args else @hash[var] end end end >> e = WrapHash.new(ENV) => # >> e.pager => "less -irs" >> e.PaGeR => "less -irs" >> e.pager = "more" => "more" >> ENV["pager"] => nil >> ENV["PAGER"] => "more" Jason Creighton