Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # c pre processor #ruby
- context = Object.new
- text = STDIN.read.lines
- text.delete_if do |l|
- if m = l.match(/^\s*#\s*ruby\s+(?<f>\w+)\s*(?<args>\(.+?\))?\s+(?<body>.+)/)
- context.instance_eval %{def #{m[:f]}#{m[:args]}\n#{m[:body]}\nend}
- end
- end
- text.each do |l|
- context.singleton_methods.each do |f|
- l.gsub! /#{f}(?:\((.+?)\))?/ do
- context.send f, *($1 || '').split(/,\s*/)
- end
- end
- l
- end
- puts text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement