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)


173
174
175
176
177
178
# File 'lib/ae/core_ext.rb', line 173

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

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

Returns:

  • (Boolean)


149
150
151
152
153
154
155
156
# File 'lib/ae/core_ext.rb', line 149

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

#throws?(sym, *args) ⇒ Boolean

Returns:

  • (Boolean)


159
160
161
162
163
164
165
166
167
168
169
# File 'lib/ae/core_ext.rb', line 159

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