Sha256: 0db1b447b06c18beacf6a9c02b08ceeaa43ab043f1c1bf676758342b4a231bc5

Contents?: true

Size: 818 Bytes

Versions: 4

Compression:

Stored size: 818 Bytes

Contents

module Kernel

  # TODO: Is there a way to do this without the eval string in block?
  # Preferably just a block and no string.

  # 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 <code>require 'facets'</code>.
  #
  # @uncommon
  #   require 'facets/kernel/demo'
  #
  def demo(out=$stdout,&block)
    out << sprintf("%-25s#=>  %s\n", expr = block.call, eval(expr, block.binding).inspect)
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/kernel/demo.rb
facets-3.1.0 lib/core/facets/kernel/demo.rb
facets-3.0.0 lib/core/facets/kernel/demo.rb
facets-2.9.3 lib/core/facets/kernel/demo.rb