public
Description: A library for safe evaluation of Ruby code based on ParseTree/RubyParser and Ruby2Ruby. Provides Rails ActionView template handlers for ERB and Haml.
Homepage: http://www.artweb-design.de
Clone URL: git://github.com/svenfuchs/safemode.git
safemode / demo.rb
100644 24 lines (16 sloc) 0.429 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'safemode'
require 'erb'
 
erb_code = %q{<% 10.times do |i| %><%= i %><% end %>}
 
raw_code = %q{
(1..10).to_a.collect do |i|
puts i
i * 2
end.join(', ')
}
 
box = Safemode::Box.new
 
puts "Doing the ERB code in safe mode\n-----"
puts box.eval(ERB.new(erb_code).src)
 
puts "\nDoing the regular Ruby code in safe mode\n-----"
puts box.eval(raw_code)
 
puts "\nOutput from regular Ruby code\n-----"
puts box.output