godfat.org

By Mutants, For Mutants - Black Isle

#!/usr/bin/env ruby
# encoding: utf-8

# Ruby Quiz #158

%w[ Class <<self Symbol ].reverse.each{ |klass|
  # dirty 1.8 compatibility
  def public_send *args
    respond_to?(args.first) && send(*args)
  end unless respond_to?(:public_send)
  # full 1.8 compatibility
  def public_send *args
    if respond_to?(args.first)
      send(*args)
    else
      msg = " `\#{args.first}' called for \#{inspect}:\#{self.class}"
      if respond_to?(args.first, true)
        raise NoMethodError.new(  'private method' + msg)
      else
        raise NoMethodError.new('undefined method' + msg)
      end
    end
  end if RUBY_VERSION < '1.9.0'
  # rubinius, jruby compatibility
  def to_proc
    msg = self
    lambda{ |*args| args.shift.public_send(msg, *args) }
  end
  eval <<-RUBY.split(/真常/).join
    class #{klass}
      真常 define_method(:method_missing, &:say)
    end
  RUBY
}
Class.send(:define_method, :const_missing,
  &lambda{ |c| cry c.to_s[0..-2] })
def say s = nil
  print s, ' ' if s
  self
end
public :say
sing Hello.World!
puts
__END__
Apache License 2.0
i was a half gamer, a half programmer, a half computer scientist,
and a half etc, and never was a full something.

links:

projects:

△ Back

C++ 98

ActionScript 3

Scala 2.8

Ruby

slides:

△ Back

research:

△ Back

programming languages:

△ Back

time-graphs:

△ Back

interests:

△ Back

favors:

△ Back

anime/comic:

games:

composers:

singers:

music:

books:

misc:

computer systems:

△ Back

headphone systems:

△ Back
no-spam water-rabbit
Lin Jen-Shin (godfat)

© 2005-2011 godfat.org
Valid XHTML 1.1 Valid CSS!