Cooler_

Ruby inline C

Jul 15th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.49 KB | None | 0 0
  1. # ruby agora fica legals neh HUIAHiuAHUAHUAH
  2. require "rubygems"
  3. require "inline"
  4. class MyTest
  5.   inline do |builder|
  6.     builder.include '<string.h>'
  7.     builder.add_compile_flags '-O3'
  8.     builder.c "
  9.  
  10. char *strrev(char *str)
  11. {
  12. char *p1, *p2;
  13.  
  14. if(! str || ! *str)
  15.  return str;
  16. for(p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
  17. {
  18.  *p1 ^= *p2;
  19.  *p2 ^= *p1;
  20.  *p1 ^= *p2;
  21. }
  22. return str;
  23. }
  24.  
  25.   "
  26.   end
  27. end
  28.  
  29. t = MyTest.new()
  30. lol = t.strrev("Yahoo")
  31. puts  lol
Advertisement
Add Comment
Please, Sign In to add comment