Created
August 8, 2012 03:58
-
-
Save technohippy/3291926 to your computer and use it in GitHub Desktop.
FizzとBuzzだけで書く_.rb系の言語
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __script__(src) | |
code = [] | |
src = src.unpack("C*").map {|c| c.ord.to_s(6).rjust(3, "0").chars.to_a } | |
src.flatten(1).map {|n| n.to_i(6) + 1 }.each do |n| | |
code.empty? || code.last.size + n + 1 >= 60 ? code << "" : code.last << " " | |
code.last << "_" * n | |
end | |
code.map! {|s| s.gsub(/_/, 'Fizz').gsub(/ /, 'Buzz')} | |
([%q(require "fizzbuzz")] + code).join("\n") | |
end | |
$code, $fragment = [], [] | |
def method_missing(mhd, *x) | |
if x.empty? | |
$code.concat($fragment.reverse) | |
$fragment.clear | |
end | |
$fragment << (mhd.to_s.size - 1).to_s | |
end | |
class Object | |
def self.const_missing(name) | |
code = name.to_s.gsub(/Fizz/, '_').gsub(/Buzz/, ' ') | |
eval code | |
end | |
end | |
at_exit do | |
$code.concat($fragment.reverse) | |
eval($code.join.scan(/.../).map {|c| c.to_i(6) }.pack("C*")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ほぼ https://github.com/mame/_ からのコピペ