Class: Object

Inherits:
BasicObject
Defined in:
lib/core/object.rb

Instance Method Summary collapse

Instance Method Details

#alias_method(new_id, original_id) ⇒ Object

Alias method



26
27
28
29
# File 'lib/core/object.rb', line 26

def alias_method(new_id, original_id)
  original = self.method(original_id).to_proc
  define_method(new_id){|*args| original.call(*args)}
end

#bm(msg, &block) ⇒ Object

Benchmark a block



32
33
34
35
36
# File 'lib/core/object.rb', line 32

def bm(msg, &block)
  t = Time.now
  block.call
  puts "#{msg}: #{Time.now-t}"
end

#cloudsObject

The clouds hash is a global hash that all objects can retrieve clouds from and they are stored by name



21
22
23
# File 'lib/core/object.rb', line 21

def clouds
  $clouds ||= {}
end

#ddputs(m = "") ⇒ Object



76
77
78
# File 'lib/core/object.rb', line 76

def ddputs(m="")
  puts "[VERY DEBUG] -- #{m.is_a?(String) ? m : m.inspect}" if very_debugging?
end

#debugging?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/core/object.rb', line 85

def debugging?
  ($DEBUGGING ||= false)
end

#do_once(&block) ⇒ Object

Do once. Takes a block. IF this block has already been run (from the run_procs array), then run it and store the block unique id in the run_procs array so it never gets run again



42
43
44
45
46
47
# File 'lib/core/object.rb', line 42

def do_once(&block)
  unless run_procs.include?(block.to_s)      
    instance_eval &block if block
    run_procs << block.to_s
  end    
end

#dputs(m = "") ⇒ Object



73
74
75
# File 'lib/core/object.rb', line 73

def dputs(m="")
  puts "[DEBUG] -- #{m.is_a?(String) ? m : m.inspect}" if debugging?
end

#instance_exec(*args, &block) ⇒ Object

Taken from www.ruby-forum.com/topic/54096 Instance eval a block with arguments



57
58
59
60
61
62
63
64
65
66
# File 'lib/core/object.rb', line 57

def instance_exec(*args, &block)
  mname = "__instance_exec_#{Thread.current.object_id.abs}"
  class << self; self end.class_eval{ define_method(mname, &block) }
  begin
    ret = send(mname, *args)
  ensure
    class << self; self end.class_eval{ undef_method(mname) } rescue nil
  end
  ret
end

#pool(name, &block) ⇒ Object

The pool method creates a pool and inserts it into the pool hash



5
6
7
8
9
10
11
# File 'lib/core/object.rb', line 5

def pool(name, &block)
  if block
    pools[name.to_s] ||= PoolParty::Pool.new(name, &block)
  else
    raise PoolParty::PoolPartyError.create("PoolError", "You must pass a block when defining a pool")
  end
end

#poolsObject

The global hash of pools



14
15
16
# File 'lib/core/object.rb', line 14

def pools
  $pools ||= {}
end

#run_procsObject

Procs that have been run already in the run_once blocks This is just a container array of procs



51
52
53
# File 'lib/core/object.rb', line 51

def run_procs
  @run_procs ||= []
end

#verbose?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/core/object.rb', line 79

def verbose?
  $TESTING ||= false
end

#very_debugging?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/core/object.rb', line 88

def very_debugging?
  ($VERY_DEBUGGING ||= false)
end

#very_verbose?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/core/object.rb', line 82

def very_verbose?
  ($VERY_VERBOSE ||= false)
end

#vputs(m = "") ⇒ Object

MESSAGES Debugging output helpers



70
71
72
# File 'lib/core/object.rb', line 70

def vputs(m="")
  puts "[INFO] -- #{m.is_a?(String) ? m : m.inspect}" if verbose?
end