Module: Kernel

Defined in:
lib/runtime/debugger.rb,
lib/utilities/kernel.rb

Instance Method Summary collapse

Instance Method Details

#debuggerObject

Starts a debugging session if ruby-debug has been loaded (call waves-server –debugger to do load it).



4
5
6
7
# File 'lib/runtime/debugger.rb', line 4

def debugger
  puts "debugger called"
  Waves::Logger.info "\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n"
end

#returning(object) {|object| ... } ⇒ Object

From Rails. This comes in handy when you want to return a value that you need to modify. So instead of the awkward:

foo = Foo.new
foo.bar = 'bar'
foo

You can just say

returning Foo.new { |foo| foo.bar = 'bar' }

Yields:

  • (object)


14
15
16
# File 'lib/utilities/kernel.rb', line 14

def returning( object, &block )
  yield object; object
end

#with(object, &block) ⇒ Object

Inspired by a question on comp.lang.ruby. Sort of like returning, except you don’t need to pass in the returnee as an argument. The drawback is that, since this relies on instance_eval, you can’t access in methods in the local scope. You can work around this by assigning values to variables, but in that case, you might be better off using returning.

Our above example would look like this:

with( Foo.new ) { bar = 'bar' }


29
30
31
# File 'lib/utilities/kernel.rb', line 29

def with( object, &block )
  object.instance_eval(&block); object
end