Class: Binding
- Inherits:
-
Object
- Object
- Binding
- Defined in:
- lib/dp.rb
Instance Method Summary collapse
-
#p(debug_str) ⇒ Object
Prints a debug string from a comma-separated string of expressions.
Instance Method Details
#p(debug_str) ⇒ Object
Prints a debug string from a comma-separated string of expressions
Parameters
-
debug_str
- The string with expressions to print
Examples
def some_method
name = 'Niclas'
@age = 38
team = ['Niclas', 'Johan', 'Hans']
d.p "name, @age, team"
# output is: 'name="Niclas", @age=38, team=["Niclas", "Johan", "Hans"]'
end
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dp.rb', line 24 def p debug_str str = '' separator = '' variables = debug_str.split(',').map { |v| v.strip } variables.each do |var| result = Kernel.eval var, self str += "#{separator}#{var}=#{result.inspect}" separator = ', ' end puts str end |