Module: Ccdk::TDump
- Included in:
- Object
- Defined in:
- lib/ccdk/tdump.rb
Overview
Create a templated representation of the object. This module can be useful For debugging objects by dumping them out to a template of your choosing. Similar in use to pp
, but more flexible so that you can display only the information that you care about.
Instance Method Summary collapse
-
#tdump(template) ⇒ Object
Convert the object to a
String
based on the provided template.
Instance Method Details
#tdump(template) ⇒ Object
Convert the object to a String
based on the provided template. Templates can be specified in several ways
-
A
String
representation of the template. -
A
String
path to a template file -
An
Erb
object of the template -
An
IO<tt> object that can be read to retrieve a template (Really anything that responds to <tt>#read
)
Parameters
-
template
- The template to use for formatting the object
Examples
# Output information to a templating string
car.tdump('I have a <%= year %> <%= make %> <%= model %>')
# Use the path to an erb template file
product.tdump('path/to/product_template.erb')
30 31 32 33 34 35 36 37 38 |
# File 'lib/ccdk/tdump.rb', line 30 def tdump(template) if template.is_a? ERB tdump_erb(template) elsif template.respond_to?(:read) tdump_io(template) elsif template.is_a? String tdump_string(template) end end |