antimac.org
Dan's homepage

Archive for July, 2009

Finally, a new version of Shup

Wednesday, July 29th, 2009

After a year of BACK BURNERING, Shup v0.27 was released into the wild last night. It includes a bunch of bug fixes and adds copy/paste functionality to the image editor.

Download it here.

Ruby: Enumerate defined classes

Monday, July 27th, 2009

Ruby has a neat method available for enumerating all constants defined within a namespace/class/module – constants().  As all classes inherit from the Object class, one can call Object.constants() to get a list of constants which can then be filtered into something useful.

For example, I had defined a bunch of *Parser classes in my code.  Rather than manually instantiate each one, I used the following to iterate over them automagically.

Object.constants().each do |const|
  if !is_my_class?(const)
    next
  end

  obj = Module.const_get(const).new()
  # do stuff here
  obj = nil
end

Simply define is_my_class?() and you’re good to go.

Ask Justin Frankel

Friday, July 24th, 2009

I guess it’s because he is old and wise but Justin just (?) launched “Ask Justin Frankel” (http://askjf.com/).  Go ask him a question!