🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

That Stupid Thing I Wrote the Other Day, part 3

Published 2010-06-17 @ 15:07

Tagged toys

Here’s a stupid little snippet:

1
2
3
4
5
6
7
8
def ENV.method_missing msg, *args
  msg = msg.to_s
  if msg =~ /=$/ then
    self[msg[0..-2]] = args.first.to_s
  else
    self[msg]
  end
end

Changes:

1
ENV["GEM_HOME"] = ENV["GEM_PATH"] = dir

into:

1
ENV.GEM_HOME = ENV.GEM_PATH = dir

The #to_s inside the setter changes:

1
ENV["BOOL"] = "1"

into:

1
ENV.BOOL = 1

Not terribly useful, but much prettier imo.