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}"')
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme