Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Ruby Programming
Previous Page Home Next Page

xmp

irb's xmp is an ``example printer''---that is, a pretty-printer that shows the value of each expression as it is run (much like the script we wrote to format the examples in this book). There is also another stand-alone xmp in the archives.

xmp can be used as follows:

require "irb/xmp"

xmp <<END artist = "Doc Severinsen" artist END
produces:
[pwd:/tc/work/ruby/ProgrammingRuby/latex]
artist = "Doc Severinsen"
    ==>"Doc Severinsen"
artist
    ==>"Doc Severinsen"

Or, it can be used as an object instance. Used in this fashion, the object maintains context between invocations:

require "irb/xmp"

x = XMP.new x.puts <<END artist = "Louis Prima" END

x.puts <<END artist END
produces:
[pwd:/tc/work/ruby/ProgrammingRuby/latex]
artist = "Louis Prima"
    ==>"Louis Prima"
artist
    ==>"Louis Prima"

You can explicitly provide a binding with either form; otherwise, xmp uses the caller's environment.

xmp code_string, abinding
XMP.new(abinding)

Note that xmp does not work with multithreading.
Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire