summaryrefslogtreecommitdiff
path: root/golf_prelude.rb
blob: 114e7dba5b0a23914861b86c4fc134c56072e14d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
SCRIPT_LINES__={}

class Object
  @@golf_hash = {}
  def method_missing m, *a, &b
    t = @@golf_hash.fetch(k = [m,self.class]) do
      r = /^#{m.to_s.gsub(/(?<=\w)(?=_)/, '\w*?')}/
      @@golf_hash[k] = (methods + private_methods).sort.find{|e|r=~e}
    end
    t ? __send__(t, *a, &b) : super
  end

  def self.const_missing c
    r = /^#{c}/
    t = constants.sort.find{|e|r=~e} and return const_get(t)
    raise NameError, "uninitialized constant #{c}", caller(1)
  end

  def h(a='H', b='w', c='!')
    puts "#{a}ello, #{b}orld#{c}"
  end

  def quine(src = $0)
    SCRIPT_LINES__[src].join
  end

  alias say puts
end

class Integer
  alias each times
  include Enumerable
end

class String
  alias / split
end