Jeff Hodges wrote:
Jeff Hodges wrote:
Yeah, its in ActiveSupport (and in facets, iirc) like so:
  > "foo_bar".classify
  => "FooBar"

Mmmf.. what we actually need is "FooBar".underscore from it now that I've found the code in Widget.

A quick version of Widget.inherited that keeps both the "nicer" version, and the older version for backward compatibility (if we care about it).

Hopefully, thunderbird won't screw up the line wrapping.

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

    meth_name = subc_str.
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase

    Shoes.class_eval %{
      def #{meth_name}(*a, &b)
        a.unshift #{subc}
        widget(*a, &b)
      end

      def #{subc_str.downcase}(*a, &b)
        #{meth_name}(*a, &b)
      end
    }
  end
--
Jeff

Reply via email to