Method: Kernel#demo
- Defined in:
- lib/core/facets/kernel/demo.rb
#demo(out = $stdout, &block) ⇒ Object
For debugging and showing examples. Currently this takes an argument of a string in a block…
demo {%{ a = [1,2,3] }}
demo {%{ a.slice(1,2) }}
demo {%{ a.map { |x| x**3 } }}
produces …
a = [1,2,3] #=> [1, 2, 3]
a.slice(1,2) #=> [2, 3]
a.map { |x| x**3 } #=> [1, 8, 27]
NOTE: This method is not a common core extension and is not loaded automatically when using require 'facets'
.
25 26 27 |
# File 'lib/core/facets/kernel/demo.rb', line 25 def demo(out=$stdout,&block) out << sprintf("%-25s#=> %s\n", expr = block.call, eval(expr, block.binding).inspect) end |