Created
June 16, 2011 20:53
-
-
Save knsmr/1030250 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require 'fileutils' | |
| File.open("./numeric.c", "r") do |klass| | |
| File.open("./numeric.tmp", "w") do |tmpfile| | |
| while line = klass.gets | |
| tmpfile.write line | |
| if line =~ /fix_to_s\(int argc, VALUE \*argv, VALUE x\)/ | |
| 2.times {tmpfile.write klass.readline} | |
| tmpfile.write <<PATCH | |
| int val; | |
| val = FIX2INT(x); | |
| if (val % 15 == 0) return rb_str_new2("FizzBuzz"); | |
| if (val % 3 == 0) return rb_str_new2("Fizz"); | |
| if (val % 5 == 0) return rb_str_new2("Buzz"); | |
| PATCH | |
| end | |
| end | |
| end | |
| end | |
| FileUtils.mv("numeric.tmp", "numeric.c") | |
| system('make') | |
| system('./ruby -ve "(1..100).each{|i| puts i}"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment