Sha256: b074a46f773217ae6215aabdbb41920b2cbb6c7398064bcda35003cf54b29500
Contents?: true
Size: 630 Bytes
Versions: 3
Compression:
Stored size: 630 Bytes
Contents
module Kernel # 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] # # TODO: Is there a way to do this without the eval string in block? # Preferably just a block and no string. def demo(out=$stdout,&block) out << sprintf("%-25s#=> %s\n", expr = block.call, eval(expr, block.binding).inspect) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
facets-2.9.0 | lib/tour/facets/kernel/demo.rb |
facets-2.9.0.pre.2 | lib/tour/facets/kernel/demo.rb |
facets-2.9.0.pre.1 | lib/tour/facets/kernel/demo.rb |