hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Friday

2005.12.30

Using Hashes to Memoize #

by why in bits

Another stellar realization from Mauricio:

 iptocountry = Hash.new do |h,ip|
   h[ip] = `geoiplookup #{ip}`.chomp.gsub(/^GeoIP Country Edition: /,"")
 end
 iptocountry.update Marshal.load(File.read("geo.cache")) rescue nil

Want to know what it does?

Continue to full post. (216 words)

Koichi's Brief Ruby Certification #

by why in bits

Koichi Sasada says if you can predict the correct output of the following, you are a great Ruby hacker. Man, that’s true!

 Const = :top
 class C
   Const = :C
 end

 C.instance_eval %{p Const}
 C.instance_eval  {p Const}
 C.module_eval   %{p Const}
 C.module_eval    {p Const}
 C.class_eval    %{p Const}
 C.class_eval     {p Const}
 eval            %{p Const}
 eval             {p Const}

Even if you don’t get the answers right, I will call you a great Ruby hacker if you can explain it. (As usual: ~sasada.)