diff options
Diffstat (limited to 'lib/puppet/util/monkey_patches.rb')
-rw-r--r-- | lib/puppet/util/monkey_patches.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index 6b5af8350..16384855a 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -21,6 +21,9 @@ class Symbol z.emit("!ruby/sym ") to_s.to_zaml(z) end + def <=> (other) + self.to_s <=> other.to_s + end end [Object, Exception, Integer, Struct, Date, Time, Range, Regexp, Hash, Array, Float, String, FalseClass, TrueClass, Symbol, NilClass, Class].each { |cls| @@ -48,3 +51,21 @@ if RUBY_VERSION == '1.8.7' end end +class Object + # The following code allows callers to make assertions that are only + # checked when the environment variable PUPPET_ENABLE_ASSERTIONS is + # set to a non-empty string. For example: + # + # assert_that { condition } + # assert_that(message) { condition } + if ENV["PUPPET_ENABLE_ASSERTIONS"].to_s != '' + def assert_that(message = nil) + unless yield + raise Exception.new("Assertion failure: #{message}") + end + end + else + def assert_that(message = nil) + end + end +end |