Class: Object

Inherits:
BasicObject
Defined in:
lib/sane/sane_random.rb,
lib/sane/pps.rb

Overview

more helpers

Instance Method Summary collapse

Instance Method Details

#_dbgObject

helper to bring up a debugger with less writing [just _dbg]



50
51
52
53
54
55
56
57
58
59
# File 'lib/sane/sane_random.rb', line 50

def _dbg
  require 'rubygems' if RUBY_VERSION < '1.9' # for ruby-debug gem
  require 'pp' # who would want debug without pp? not I
  begin
    require 'ruby-debug'
    debugger
  rescue LoadError => e
    throw "unable to load ruby-debug gem for _dbg... #{e}"
  end
end

#assert(should_be_true, string = nil) ⇒ Object

ex: assert(some statement) or assert(some statement, “some helper string”)



43
44
45
46
47
# File 'lib/sane/sane_random.rb', line 43

def assert(should_be_true, string = nil)
  if(!should_be_true)
    raise "assertion failed #{string}"
  end
end

#in?(collection) ⇒ Boolean

a helper for collection.include?

Returns:

  • (Boolean)


36
37
38
# File 'lib/sane/sane_random.rb', line 36

def in? collection
  collection.include?(self)
end

#pps(*args) ⇒ Object

a method that outputs several items on one line similar to using pp, this space separates the items passed in and writes them to one line sputs 1,2,3

> 1 2 3



6
7
8
9
10
11
12
13
# File 'lib/sane/pps.rb', line 6

def pps *args
  for arg in args
    out = arg.to_s
    print out
    print " " if out[-1..-1] != " "
  end
  puts
end

#singleton_classObject



61
62
63
# File 'lib/sane/sane_random.rb', line 61

def singleton_class
  class << self; self; end
end