Class: Hyperion::Util
- Inherits:
-
Object
- Object
- Hyperion::Util
- Defined in:
- lib/hyperion/aux/util.rb
Defined Under Namespace
Classes: CallCcError
Class Method Summary collapse
-
.callcc ⇒ Object
reimplement callcc because ruby has deprecated it.
- .guard_param(value, what, expected_type = nil, &pred) ⇒ Object
- .nil_if_error ⇒ Object
Class Method Details
.callcc ⇒ Object
reimplement callcc because ruby has deprecated it
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hyperion/aux/util.rb', line 19 def self.callcc() in_scope = true cont = proc do |retval| unless in_scope raise "Cannot invoke this continuation. Control has left this continuation's scope." end raise CallCcError.new(retval) end yield(cont) rescue CallCcError => e e.retval ensure in_scope = false end |
.guard_param(value, what, expected_type = nil, &pred) ⇒ Object
13 14 15 16 |
# File 'lib/hyperion/aux/util.rb', line 13 def self.guard_param(value, what, expected_type=nil, &pred) pred ||= proc { |x| x.is_a?(expected_type) } pred.call(value) or fail BugError, "You passed me #{value.inspect}, which is not #{what}" end |
.nil_if_error ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/hyperion/aux/util.rb', line 5 def self.nil_if_error begin yield rescue StandardError return nil end end |