Issue #15596 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Rejected

As nobu stated, the current behavior is expected in regards to not printing a newline if no arguments are given, and the documentation is accurate for the current behavior.  It states `converts each of the messages to strings, appends a newline character to the string if the string does not end in a newline, and calls Warning.warn with the string.`. To me, that implies if there are no messages/arguments, it does not do anything.

It is true that `warn` is different than `puts` in how a zero argument call is handled. `warn` it is similar to `p` in this regard.  `puts` is specifically documented as adding a newline for no arguments (`If called without arguments, outputs a single newline`), and `warn` is not.

----------------------------------------
Bug #15596: Kernel.warn without arguments should do the same as Kernel.warn(nil)
https://bugs.ruby-lang.org/issues/15596#change-78451

* Author: kke (Kimmo Lehto)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Kernel.warn without arguments does not print an empty line to $stderr.

This is inconsistent with `Kernel.puts` and it feels weird, because it does not act like a regular Ruby method would (if it was written in Ruby instead of C, it would probably be defined like `def warn(msg = nil)` and calling it with or without nil as argument would make no difference)

### Expected behavior:

```
irb(main):001:0> warn nil

=> nil
irb(main):002:0> warn

=> nil
```

### Actual behavior:

```
irb(main):001:0> warn nil

=> nil
irb(main):002:0> warn
=> nil
```






-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>