diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
commit | d0233291bc8a5068e52c69c210e5979e5324b5bc (patch) | |
tree | 7d9459449c33792c63eeb7baa071e76352e0baab /trunk/golf_prelude.rb | |
parent | 0dc342de848a642ecce8db697b8fecd83a63e117 (diff) | |
parent | 72eaacaa15256ab95c3b52ea386f88586fb9da40 (diff) |
re-adding tag v1_9_0_4 as an alias of trunk@18848v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/golf_prelude.rb')
-rw-r--r-- | trunk/golf_prelude.rb | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/trunk/golf_prelude.rb b/trunk/golf_prelude.rb deleted file mode 100644 index 15c1832a39..0000000000 --- a/trunk/golf_prelude.rb +++ /dev/null @@ -1,104 +0,0 @@ -class Object - @@golf_hash = {} - def method_missing m, *a, &b - t = @@golf_hash[ [m,self.class] ] ||= matching_methods(m)[0] - t ? __send__(t, *a, &b) : super - end - - def matching_methods(s='', m=callable_methods) - r=/^#{s.to_s.gsub(/./){"(.*?)"+Regexp.escape($&)}}/ - m.grep(r).sort_by do |i| - i.to_s.match(r).captures.map(&:size)<<i - end - end - - def self.const_missing c - t = @@golf_hash[ [c,self.class] ] ||= matching_methods(c,constants)[0] - t and return const_get(t) - raise NameError, "uninitialized constant #{c}", caller(1) - end - - def shortest_abbreviation(s='', m=callable_methods) - s=s.to_s - our_case = (?A..?Z)===s[0] - if m.index(s.to_sym) - 1.upto(s.size){|z|s.scan(/./).combination(z).map{|trial| - next unless ((?A..?Z)===trial[0]) == our_case - trial*='' - return trial if matching_methods(trial,m)[0].to_s==s - }} - else - nil - end - end - - def callable_methods - self.class == Object ? methods + private_methods : methods - end - - private - - def h(a='H', b='w', c='!') - puts "#{a}ello, #{b}orld#{c}" - end - - alias say puts - - def do_while - 0 while yield - end - - def do_until - 0 until yield - end -end - -class Array - alias old_to_s to_s - alias to_s join -end - -class FalseClass - alias old_to_s to_s - def to_s - "" - end -end - -class Integer - alias each times - include Enumerable -end - -class String - alias / split - - def to_a - split('') - end - - (Array.instance_methods-instance_methods-[:to_ary,:transpose,:flatten,:flatten!,:compact,:compact!,:assoc,:rassoc]).each{|meth| - eval"def #{meth}(*args, &block) - a=to_a - result = a.#{meth}(*args, &block) - replace(a.join) - if result.class == Array - Integer===result[0] ? result.pack('c*') : result.join - elsif result.class == Enumerator - result.map(&:join).to_enum - else - result - end - end" - } -end - -class Enumerator - alias old_to_s to_s - (Array.instance_methods-instance_methods-[:replace]+[:to_s]).each{|meth| - eval"def #{meth}(*args, &block) - to_a.#{meth}(*args, &block) - end" - } - alias inspect old_to_s -end |