ruby-changes:3254
From: ko1@a...
Date: 28 Dec 2007 10:07:40 +0900
Subject: [ruby-changes:3254] knu - Ruby:r14747 (trunk): * golf_prelude.rb (Object.const_missing): Auto-complete constants.
knu 2007-12-28 10:07:21 +0900 (Fri, 28 Dec 2007) New Revision: 14747 Modified files: trunk/ChangeLog trunk/golf_prelude.rb Log: * golf_prelude.rb (Object.const_missing): Auto-complete constants. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/golf_prelude.rb?r1=14747&r2=14746 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14747&r2=14746 Index: ChangeLog =================================================================== --- ChangeLog (revision 14746) +++ ChangeLog (revision 14747) @@ -1,3 +1,7 @@ +Fri Dec 28 10:06:54 2007 Akinori MUSHA <knu@i...> + + * golf_prelude.rb (Object.const_missing): Auto-complete constants. + Fri Dec 28 01:55:04 2007 Nobuyoshi Nakada <nobu@r...> * transcode.c (transcode_dispatch): allows transcoding from/to Index: golf_prelude.rb =================================================================== --- golf_prelude.rb (revision 14746) +++ golf_prelude.rb (revision 14747) @@ -5,6 +5,12 @@ t ? __send__(t, *a, &b) : super end + def self.const_missing c + r = /^#{c}/ + t = constants.sort.find{|e|r=~e} + t ? const_get(t) : superclass.const_get(c) + end + def h(a='H', b='w', c='!') puts "#{a}ello, #{b}orld#{c}" end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml