4 verbose, $VERBOSE = $VERBOSE, nil
5 def method_missing m, *a, &b
6 t = @@golf_hash[ [m, self.class] ] ||= matching_methods(m)[0]
8 __send__(t, *a) {|*args|
9 b.binding.eval("proc{|golf_matchdata| $~ = golf_matchdata }").call($~) if $~
13 t ? __send__(t, *a, &b) : super
18 def matching_methods(s = '', m = callable_methods)
19 r = /^#{s.to_s.gsub(/./){"(.*?)" + Regexp.escape($&)}}/
20 m.grep(r).sort_by do |i|
21 i.to_s.match(r).captures.map(&:size) << i
25 def self.const_missing c
26 t = @@golf_hash[ [c,self.class] ] ||= matching_methods(c, constants)[0]
27 t and return const_get(t)
28 raise NameError, "uninitialized constant #{c}", caller(1)
31 def shortest_abbreviation(s = '', m = callable_methods)
33 our_case = (?A..?Z) === s[0]
35 1.upto(s.size){|z| s.scan(/./).combination(z).map{|trial|
36 next unless ((?A..?Z) === trial[0]) == our_case
38 return trial if matching_methods(trial, m)[0].to_s == s
46 self.class == Object ? methods + private_methods : methods
51 def h(a = 'H', b = 'w', c = '!')
52 puts "#{a}ello, #{b}orld#{c}"
56 1.upto(m){|n|puts'FizzBuzz
57 '[i=n**4%-15,i+13]||n}
95 (Array.instance_methods - instance_methods - %i[to_ary transpose flatten flatten! compact compact! assoc rassoc]).each{|meth|
97 def #{meth}(*args, &block)
99 result = a.#{meth}(*args, &block)
101 if result.class == Array
102 Integer === result[0] ? result.pack('c*') : result.join
103 elsif result.class == Enumerator
104 result.map(&:join).to_enum
114 (Array.instance_methods - instance_methods - [:replace] + [:to_s]).each{|meth|
116 def #{meth}(*args, &block)
117 to_a.#{meth}(*args, &block)
120 alias old_inspect inspect
121 alias inspect old_to_s
125 def call(*args, &block)
127 recv.__send__(self, *args, &block)