On Mon, Sep 29, 2008 at 10:39 PM, Jeff Hodges <[EMAIL PROTECTED]> 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
fwiw, I would do the setup of the string differently:
class_name = subc.name[/(::)?(\w+)$/, 2]
That should never return nil. It would break down with more than one
namespace, though, unless only using the actual class name were the
desired behavior. Using namespaces below "Shoes" could be useful for
pseudo-namespacing the generated methods.
Back on point, I dunno if throwing a patch like this in right away
would be best if some other namespace related changes weren't made. I
kind of want _why to weigh in on my question from the other thread
about how necessary and flexible the auto-namespacing behavior we have
now is.
I think Bluebie mentioned how the current behavior is similar to how
Camping does things. I remember bumping into that and struggling for a
little bit, and ultimately I don't think it's necessarily horrible if
you have to be aware of this wrinkle in the Ruby environment Shoes
creates. But it certainly would be better if we could at least help
avoid people being caught up on it like we were.
--
Seth Thomas Rasmussen
http://greatseth.com