Class: Proc

Inherits:
Object show all
Defined in:
lib/vendor/bacon.rb,
lib/ramaze/snippets/proc/locals.rb

Instance Method Summary collapse

Instance Method Details

#change?Boolean

Returns:

  • (Boolean)


229
230
231
232
233
234
# File 'lib/vendor/bacon.rb', line 229

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

#localsObject

returns a hash of localvar/localvar-values from proc, useful for template engines that do not accept bindings/proc and force passing locals via hash

usage: x = 42; p Proc.new.locals #=> {'x'=> 42}


7
8
9
# File 'lib/ramaze/snippets/proc/locals.rb', line 7

def locals
  instance_eval('binding').locals
end

#raise?(*exceptions) ⇒ Boolean

Returns:

  • (Boolean)


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/vendor/bacon.rb', line 205

def raise?(*exceptions)
  exceptions = [RuntimeError]  if exceptions.empty?
  call

# Only to work in 1.9.0, rescue with splat doesn't work there right now
rescue Object => e
  case e
  when *exceptions
    e
  else
    raise e
  end
else
  false
end

#throw?(sym) ⇒ Boolean

Returns:

  • (Boolean)


221
222
223
224
225
226
227
# File 'lib/vendor/bacon.rb', line 221

def throw?(sym)
  catch(sym) {
    call
    return false
  }
  return true
end