Chauk-Mean Proum
2009-Feb-13 16:22 UTC
[wxruby-development] About predicate methods convention for wxRuby-2.0
Hi all, wxRuby is already good at complying with Ruby conventions for predicate methods : Foo#is_ready => can be also used as Foo#ready? I''m currently improving the RichTextCtrl sample and I''m using several methods like : can_undo, can_redo, ... There are also methods like has_selection, has_character_attributes, ... For these methods, what about adding aliases with an ending ? I''d really prefer write something like : if my_richtextctrl.can_undo? .... This can be defined as a general naming rule scheme. Cheers, Chauk-Mean.
Mario Steele
2009-Feb-14 00:35 UTC
[wxruby-development] About predicate methods convention for wxRuby-2.0
Should be fairly easy to modify in the existing system. As it sits now, the way we get around some things, is by simply utilizing method_missing() method. I don''t see why it can''t be regex''ed to determin if it should be a question. I''m thinking something like: if sym.to_s =~ /[can|has]_[\w+|_]+\?/ sym = (sym.to_s[0..-2]).to_sym self.__send__(sym,*args) end On Fri, Feb 13, 2009 at 10:22 AM, Chauk-Mean Proum <chauk.mean at gmail.com>wrote:> Hi all, > > wxRuby is already good at complying with Ruby conventions for > predicate methods : > Foo#is_ready => can be also used as Foo#ready? > > I''m currently improving the RichTextCtrl sample and I''m using several > methods like : > can_undo, can_redo, ... > There are also methods like has_selection, has_character_attributes, ... > > For these methods, what about adding aliases with an ending ? > I''d really prefer write something like : > > if my_richtextctrl.can_undo? > .... > > This can be defined as a general naming rule scheme. > > Cheers, > > Chauk-Mean. > _______________________________________________ > wxruby-development mailing list > wxruby-development at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-development >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-development/attachments/20090213/e1cd4542/attachment.html>
Alex Fenton
2009-Feb-14 10:14 UTC
[wxruby-development] About predicate methods convention for wxRuby-2.0
Chauk-Mean Proum wrote:> Hi all, > > wxRuby is already good at complying with Ruby conventions for > predicate methods : > Foo#is_ready => can be also used as Foo#ready? > > I''m currently improving the RichTextCtrl sample and I''m using several > methods like : > can_undo, can_redo, ... > There are also methods like has_selection, has_character_attributes, ... > > For these methods, what about adding aliases with an ending ?I''m in favour of this, and of doing it how Mario suggests. There are other classes that would benefit eg Window#has_style. I''ll put a patch in later today, unless you want to go ahead and do it first alex
Chauk-Mean Proum
2009-Feb-14 13:06 UTC
[wxruby-development] About predicate methods convention for wxRuby-2.0
Hi Mario & Alex, 2009/2/14, Alex Fenton>> For these methods, what about adding aliases with an ending ? > > I''m in favour of this, and of doing it how Mario suggests. There are > other classes that would benefit eg Window#has_style.Yes indeed.>I''ll put a patch in later today, unless you want to goahead and do it first I''m not at home and I don''t have full access to internet. So put a patch on behalf me :-) Chauk-Mean
Alex Fenton
2009-Feb-14 21:34 UTC
[wxruby-development] About predicate methods convention for wxRuby-2.0
Chauk-Mean Proum wrote:> I''m not at home and I don''t have full access to internet. > So put a patch on behalf me :-)Done. BTW, are you subscribed to wxruby-svn-commits? a
Chauk-Mean Proum
2009-Feb-15 17:37 UTC
[wxruby-development] About predicate methods convention for wxRuby-2.0
Hi, 2009/2/14, Alex Fenton <alex at pressure.to>:> Chauk-Mean Proum wrote: > > I''m not at home and I don''t have full access to internet. > > So put a patch on behalf me :-) > > > > Done. BTW, are you subscribed to wxruby-svn-commits?Not yet but I will do it. Until now, I was just following the corresponding mailing list archive. Regarding this patch, will you also update the wxRuby overview doc page ? I can do it tomorrow if you want. Cheers. Chauk-Mean.