Top Level Namespace

Defined Under Namespace

Classes: StandardError, SystemCallError, Ugh

Instance Method Summary collapse

Instance Method Details

#ugh(short_message = 'unspecified ugh', **attr) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ugh.rb', line 42

def ugh short_message = 'unspecified ugh', **attr
  if short_message.is_a? Class then
    # Uh-oh, it's not a short message at all but an exception
    # class (or so we should hope).  Let's instantiate it.
    raise short_message.new(**attr)
  else
    raise Ugh.new(short_message, **attr)
  end
end

#ugh?(klass = Ugh, **attributes) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ugh.rb', line 55

def ugh? klass = Ugh, **attributes
  begin
    return yield
  rescue klass => exception
    evaluated_attributes = {}
    attributes.each_pair do |name, value|
      if value.is_a? Proc then
        unless exception.attributes.has_key? name then
          value = value.call
        else
          value = nil
        end
      end
      evaluated_attributes[name] = value
    end
    exception.attributes =
        evaluated_attributes.merge exception.attributes
    raise exception
  end
end