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 / lib / safemode / core_ext.rb
100644 39 lines (35 sloc) 0.874 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Kernel
  def silently(&blk)
    old_verbose, $VERBOSE = $VERBOSE, nil
    yield
    $VERBOSE = old_verbose
  end
end
 
class Module
  def undef_methods(*methods)
    methods.each { |name| undef_method(name) }
  end
end
 
class Object
  def to_jail
    Safemode.jail self
  end
end
 
# As every call to an object in the eval'ed string will be jailed by the
# parser we don't need to "proactively" jail arrays and hashes. Likewise we
# don't need to jail objects returned from a jail. Doing so would provide
# "double" protection, but it also would break using a return value in an if
# statement, passing them to a Rails helper etc.
 
# class Array
# def to_jail
# Safemode.jail collect{ |obj| obj.to_jail }
# end
# end
#
# class Hash
# def to_jail
# hash = {}
# collect{ |key, obj| hash[key] = obj.to_jail}
# Safemode.jail hash
# end
# end