Class: Proc

Inherits:
Object show all
Defined in:
lib/ae/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#change?Boolean

TODO: Put in facets? TODO: wrong place, change yield?

Returns:

  • (Boolean)


165
166
167
168
169
170
# File 'lib/ae/core_ext.rb', line 165

def change?
  pre_result = yield
  called = call
  post_result = yield
  pre_result != post_result
end

#raises?(exception = Exception, *args) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
# File 'lib/ae/core_ext.rb', line 141

def raises?(exception=Exception, *args)
  begin
    call(*args)
    false
  rescue exception => error
    exception === error
  end
end

#throws?(sym, *args) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ae/core_ext.rb', line 151

def throws?(sym, *args)
  catch(sym) do
    begin
      call(*args)
    rescue ArgumentError  # 1.9 exception
    rescue NameError      # 1.8 exception
    end
    return false
  end
  return true
end