Module: Rafini

Defined in:
lib/rafini.rb,
lib/rafini/hash.rb,
lib/rafini/array.rb,
lib/rafini/empty.rb,
lib/rafini/string.rb,
lib/rafini/integer.rb,
lib/rafini/exception.rb,
lib/rafini/odometers.rb

Defined Under Namespace

Modules: Array, Empty, Exception, Hash, Integer, Odometers, String

Constant Summary collapse

VERSION =
'2.0.0'

Class Method Summary collapse

Class Method Details

.bang!(message = nil, bang = Exception, &block) ⇒ Object

Module version of puts bang! Returns either the value or error of the block.

value = Rafini.bang!('Ooops! Not perfect?') do
  # Perfect code here...
end


32
33
34
35
36
37
38
39
40
# File 'lib/rafini/exception.rb', line 32

def Rafini.bang!(message=nil, bang=Exception, &block)
  value = nil
  begin
    value = block.call
  rescue bang => value
    value.puts(message)
  end
  return value
end

.thread_bang!(header = nil, bang = Exception, &block) ⇒ Object

The Thread wrapped version of bang! I often do

Thread.new do
  begin
    ... stuff ..
  rescue Exception
    puts 'blah blah...'
    puts $!.message if $VERBOSE
    puts $!.backtrace if $DEBUG
  end
end

With the following below, I’ll be able to say Rafini.thread_bang!(‘blah blah…’){ …stuff… }



55
56
57
# File 'lib/rafini/exception.rb', line 55

def Rafini.thread_bang!(header=nil, bang=Exception, &block)
  Thread.new{Rafini.bang!(header, bang, &block)}
end