Class: Object

Inherits:
BasicObject
Defined in:
lib/sane/sane_random.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'
  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

#aliash(hash) ⇒ Object



74
75
76
77
78
# File 'lib/sane/sane_random.rb', line 74

def aliash hash
  hash.each_pair {|new, old|
    alias_method new, old
  }
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

#singleton_classObject



80
81
82
# File 'lib/sane/sane_random.rb', line 80

def singleton_class
  class << self; self; end
end

#sputs(*args) ⇒ Object

a method that outputs several items on one line similar to Java’s println, but it adds spaces between items, ex: sputs 1,2,3

> 1 2 3



65
66
67
68
69
70
71
72
# File 'lib/sane/sane_random.rb', line 65

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