ruby picture

RCR 174: Allow #p to pass through its argument(s)

Submitted by transami (Sun Dec 07 21:12:05 UTC 2003)

Abstract

This is a legacy RCR from Ruby Garden, submitted by transami. Matz has declared these RCRs obsolete, and asked that their authors resubmit them in the new format.

Often when debugging, one wants to use p to inspect an object. But if that object lies within some other code and dosen't have a specific variable assigned to it, one has to create a temporary variable to do it:


    
  x.concat(y.upcase)

    

To inspect y.upcase one has to do:


    
  y_tmp = y.upcase
  p y_tmp
  x.concat(y_tmp)

    

It would be much nicer if p would return the argument(s) it was given, so we could simply do this instead:


    
  x.concat(p(y.upcase))

    

Problem

(RCR imported from old format)

Proposal

Analysis

(RCR imported from old format)

Implementation

(RCR imported from old format)
ruby picture
Comments Current voting

Re: Allow #p to pass through its argument(s) (marcus_erronius, 2003-12-08 23:55:19)

This is only for debugging, right? so shouldn't the code look like this anyway?

p y.upcase if $DEBUG
x.concat(y.upcase)

if you really need p to return it's arguments, you could just homebrew one that does.

Have home brewed, that's why I suggest (transami, 2003-12-09 04:31:36)

Indeed I have homebrewed and found it very very useful, so that's why I've suggested it.

As for $DEBUG, that makes sense for longer term debugging needs. But often one is just "spot inspecting" to see what kind of output is being produced to make sure the code is coming out as expected/why its not coming out as expected.


Strongly opposed 0
Opposed 0
Neutral 0
In favor 0
Strongly advocate 0
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .