Jeff Hodges wrote:
Seth Thomas Rasmussen wrote:
Yes, I think this is because of how the dynamic methods for making
widgets are created. It assumes everything is defined within Shoes
e.g. Shoes::Wodgetizer.

  def Widget.inherited subc
    Shoes.class_eval %{
      def #{subc.to_s[/::(\w+)$/, 1].
            gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
            gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase}(*a, &b)
        a.unshift #{subc}
        widget(*a, &b)
      end
    }
  end

So, considering an example class name like "Wodgetizer", without the
Shoes namespace, I think the gsub error is when
"Wodgetizer"[/::(\w+)$/, 1] returns nil.


Yep, just found this, too. Here's a working version of Widget.inherited.

def Widget.inherited subc
    subc_str = subc.to_s[/::(\w+)$/, 1]
    subc_str ||= subc.to_s

    Shoes.class_eval %{
      def #{subc_str.
            gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
            gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase}(*a, &b)
        a.unshift #{subc}
        widget(*a, &b)
      end
    }
  end

Er.. those first two lines can be joined with ||. Yeesh.
--
Jeff

Reply via email to