On Fri, 22 Aug 2003 05:03:51 +0900
"Hal E. Fulton" <hal9000 / hypermetrics.com> 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)
=> #<WrapHash:0x402b5fe4 @hash={ snipped big environment inspect }>
>> e.pager
=> "less -irs"
>> e.PaGeR
=> "less -irs"
>> e.pager = "more"
=> "more"
>> ENV["pager"]
=> nil
>> ENV["PAGER"]
=> "more"

Jason Creighton