Sha256: 3d2d483f6bbc3d07ffa5923a19a2a26370a92ad274aa4cae8b8533c612301658

Contents?: true

Size: 634 Bytes

Versions: 7

Compression:

Stored size: 634 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

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/kernel/demo.rb
facets-2.4.1 lib/facets/kernel/demo.rb
facets-2.4.2 lib/core/facets/kernel/demo.rb
facets-2.4.3 lib/core/facets/kernel/demo.rb
facets-2.4.4 lib/core/facets/kernel/demo.rb
facets-2.4.5 lib/core/facets/kernel/demo.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/kernel/demo.rb