intinig / chuck_norris

The Chuck Norris Ruby Class

This URL has Read+Write access

Giovanni Intini (author)
Fri Jun 13 04:18:44 -0700 2008
chuck_norris / chuck_norris.rb
100644 21 lines (19 sloc) 0.739 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class ChuckNorris
  def initialize
    file, line, method = caller[0].split ":"
    method = method.match(/`(.*)'/)[1]
    source = File.readlines(file)
    pointer = line.to_i - 1
    (line.to_i - 1).downto(0) do |i|
      break if source[i].match(/class (.*)\s/)
    end
    return "Ah, nice try." if $1 == "ChuckNorris"
    puts "No one initializes Chuck Norris, do you understand #{$1}? No one."
    puts "Chuck Norris roundhouse kicks #{$1} so strong that it kills all his siblings too."
    ObjectSpace.each_object(ObjectSpace.const_get($1)) {|o| o = nil}
  end
 
  def self.inherited(subclass)
    puts "Understand me, #{subclass}, no one inherits from Chuck Norris, no one."
    raise "CannotSubClassTheChuckNorris"
  end
end