Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.join("\n") doesn't work without puts/print/p #104

Closed
utkarsh2102 opened this issue May 3, 2020 · 3 comments
Closed

Array.join("\n") doesn't work without puts/print/p #104

utkarsh2102 opened this issue May 3, 2020 · 3 comments

Comments

@utkarsh2102
Copy link

Hi,

Here's one instance:

irb(main):001:0> x = [1,12,123]
irb(main):002:0> x.join("\n")
=> "1\n12\n123"

However, it works fine if used with puts:

irb(main):003:0> x = [1,12,123]
irb(main):004:0> puts x.join("\n")
1
12
123
=> nil

Shouldn't it be working w/o puts/print/p, too?
I'll be happy to raise a PR, too, if you concur with this?
(P.S. I am not sure if that's a bug or a feature)

@nobu
Copy link
Member

nobu commented May 3, 2020

How you expect it to “work”?

@yuki24
Copy link
Member

yuki24 commented May 3, 2020

This is by design. In your first example, it's the REPL displaying the actual, understandable representation of an object while the second example sends it to STDIO with no modification. They exist for different purposes and I'd be surprised if there is no distinction between these two.

@yuki24 yuki24 closed this as completed May 3, 2020
@utkarsh2102
Copy link
Author

Hi Yuki,

This is by design. In your first example, it's the REPL displaying the actual, understandable representation of an object while the second example sends it to STDIO with no modification. They exist for different purposes and I'd be surprised if there is no distinction between these two.

Thank you, that makes sense! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants