[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Kernel#p and output record separator.

Michael Fellinger

7/11/2006 7:28:00 AM

On Tuesday 11 July 2006 16:16, Minkoo Seo wrote:
> Hi.
>
> ri Kernel#p shows this:
>
> --------------------------------------------------------------- Kernel#p
> p(obj, ...) => nil
> ------------------------------------------------------------------------
> For each object, directly writes _obj_.+inspect+ followed by the
> current output record separator to the program's standard output.
>
> S = Struct.new(:name, :state)
> s = S['dave', 'TX']
> p s
>
> _produces:_
>
> #<S name="dave", state="TX">
>
> But when I run the following:
>
> $cat tmp.rb
> print $> $ ruby tmp.rb
> nil$
>
> Namely, Kernel#p is expected to print 'current output record separator',
> but current output separator is just *nil*.
>
> What I've done in the wrong way here? Is the ri document written wrongly?

manveru@pi ~> irb
p $nil
# nil
p $/
"\n"
# nil

guess you just have a typo there :)
remember, the $/ is a jedi that just waits to attack and to slice output...
it's not the output being attacked :)

stupid way to remember... but maybe it helps - imho one shoulnd't have to
remember that stuff anyway

>
> Sincerely,
> Minkoo Seo

1 Answer

Logan Capaldo

7/12/2006 5:12:00 AM

0


On Jul 12, 2006, at 12:30 AM, Minkoo Seo wrote:

> I should have to mention this problem explicitly.
>
> AFAIK, $/ is 'input record separator' while $\ is 'output record
> separator.'
> And the problem is:
>
> $ruby -e 'p "a"'
> "a"
> $
>
> As you can see p is printing new line character. But the spec says
> that
> p is supposed to print 'output record separator' after printing out
> given
> arguments.
>
> Let's see what current output record separator is...
>
> $ruby -e 'p $\'
> nil
> $
>
> Surprisingly, $\, output record separator, is nil while Kernel#p
> printed new
> line.
>
> So I guess one of the following holds:
> (1) p prints new line instead of output record separator.
> (2) Somehow, $\ is converted into newline while Kernel#p is running
> (3) $\ is not a output record separator, actually.
>
> Any idea?
>
> - Minkoo Seo
>
>
>

Ack, top posting evil.

$\ is the output record separator if print is any indicator

% cat outputsep.rb
$\ = ":"
print 1
puts


% ruby outputsep.rb
1:

I think maybe the docs lie. Looking at the C code, p uses
rb_default_rs (when maybe they meant to use rb_output_rs?)