SHARE
TWEET

Untitled

a guest Mar 26th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # c pre processor #ruby
  2.  
  3. context = Object.new
  4. text = STDIN.read.lines
  5. text.delete_if do |l|
  6.   if m = l.match(/^\s*#\s*ruby\s+(?<f>\w+)\s*(?<args>\(.+?\))?\s+(?<body>.+)/)
  7.     context.instance_eval %{def #{m[:f]}#{m[:args]}\n#{m[:body]}\nend}
  8.   end
  9. end
  10. text.each do |l|
  11.   context.singleton_methods.each do |f|
  12.     l.gsub! /#{f}(?:\((.+?)\))?/ do
  13.       context.send f, *($1 || '').split(/,\s*/)
  14.     end
  15.   end
  16.   l
  17. end
  18. puts text
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top