class Hyperion::Util

Public Class Methods

callcc() { |cont| ... } click to toggle source

reimplement callcc because ruby has deprecated it

# 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) click to toggle source
# 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() { || ... } click to toggle source
# File lib/hyperion/aux/util.rb, line 5
def self.nil_if_error
  begin
    yield
  rescue StandardError
    return nil
  end
end