diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-28 01:07:21 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-28 01:07:21 +0000 |
commit | 0ab07135c22370e38fedba81d43951a0691a2aa3 (patch) | |
tree | 8de457dd17da2696d627ba9d951d1152ed19a54f | |
parent | b9aa4d6ee84459c6b394defbebf04eded2e1b83c (diff) | |
download | ruby-0ab07135c22370e38fedba81d43951a0691a2aa3.tar.gz ruby-0ab07135c22370e38fedba81d43951a0691a2aa3.tar.xz ruby-0ab07135c22370e38fedba81d43951a0691a2aa3.zip |
* golf_prelude.rb (Object.const_missing): Auto-complete constants.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | golf_prelude.rb | 6 |
2 files changed, 10 insertions, 0 deletions
@@ -1,3 +1,7 @@ +Fri Dec 28 10:06:54 2007 Akinori MUSHA <knu@iDaemons.org> + + * golf_prelude.rb (Object.const_missing): Auto-complete constants. + Fri Dec 28 01:55:04 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> * transcode.c (transcode_dispatch): allows transcoding from/to diff --git a/golf_prelude.rb b/golf_prelude.rb index 602767a5d..59b5ffc34 100644 --- a/golf_prelude.rb +++ b/golf_prelude.rb @@ -5,6 +5,12 @@ class Object 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 |