3 def method_missing m, *a, &b
4 t = @@golf_hash[ [m,self.class] ] ||= matching_methods(m)[0]
5 t ? __send__(t, *a, &b) : super
8 def matching_methods(s='', m=callable_methods)
9 r=/^#{s.to_s.gsub(/./){"(.*?)"+Regexp.escape($&)}}/
10 m.grep(r).sort_by do |i|
11 i.to_s.match(r).captures.map(&:size)<<i
15 def self.const_missing c
16 t = @@golf_hash[ [c,self.class] ] ||= matching_methods(c,constants)[0]
17 t and return const_get(t)
18 raise NameError, "uninitialized constant #{c}", caller(1)
21 def shortest_abbreviation(s='', m=callable_methods)
23 our_case = (?A..?Z)===s[0]
25 1.upto(s.size){|z|s.scan(/./).combination(z).map{|trial|
26 next unless ((?A..?Z)===trial[0]) == our_case
28 return trial if matching_methods(trial,m)[0].to_s==s
36 self.class == Object ? methods + private_methods : methods
41 def h(a='H', b='w', c='!')
42 puts "#{a}ello, #{b}orld#{c}"
80 (Array.instance_methods-instance_methods-[:to_ary,:transpose,:flatten,:flatten!,:compact,:compact!,:assoc,:rassoc]).each{|meth|
81 eval"def #{meth}(*args, &block)
83 result = a.#{meth}(*args, &block)
85 if result.class == Array
86 Integer===result[0] ? result.pack('c*') : result.join
87 elsif result.class == Enumerable::Enumerator
88 result.map(&:join).to_enum
96 class Enumerable::Enumerator
98 (Array.instance_methods-instance_methods-[:replace]+[:to_s]).each{|meth|
99 eval"def #{meth}(*args, &block)
100 to_a.#{meth}(*args, &block)
103 alias inspect old_to_s