Forum: Ruby Strange print

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A8ef16002e25befade01d6da7728ccca?d=identicon&s=25 Valerij Kirjanov (python)
on 2006-01-31 16:09
Hi all!
I have some text in russian. Then I've print it with puts I saw beatiful
text, but then use p operator text is "\353\317\314\314\305\304\326".
How can I solve problem, because when using iconv the problem is same?
Fe9b2d0628c0943af374b2fe5b320a82?d=identicon&s=25 Eero Saynatkari (rue)
on 2006-01-31 19:41
Valerij Kirjanov wrote:
> Hi all!
> I have some text in russian. Then I've print it with puts I saw beatiful
> text, but then use p operator text is "\353\317\314\314\305\304\326".
> How can I solve problem, because when using iconv the problem is same?

The difference between puts obj and p obj is that the
former uses obj.to_s and the latter obj.inspect. Is
there a specific reason why you need to use p instead
of puts or did I misunderstand you?


E
5befe95e6648daec3dd5728cd36602d0?d=identicon&s=25 Robert Klemme (Guest)
on 2006-02-01 23:46
(Received via mailing list)
Valerij KIR wrote:
> Hi all!
> I have some text in russian. Then I've print it with puts I saw
> beatiful text, but then use p operator text is
> "\353\317\314\314\305\304\326". How can I solve problem, because when
> using iconv the problem is same?

p uses String#inspect which I believe will always print something that
can
be safely interpreted as a Ruby string on 7 bit ASCII.  You should use
puts instead of p - p is really rather a debugging / inspection untility
but not meant for normal program output (IMHO).

Kind regards

    robert
This topic is locked and can not be replied to.