gvim
(gvim)
18 January 2014 19:47
1
'print' seems to handle $_ differently 'puts':
fh = open './file.txt'
while fh.gets
print if ~ /\b\w{2}\b/
end
;=> prints matching lines
fh = open './file.txt'
while fh.gets
puts if ~ /\b\w{2}\b/
end
;=> prints a blank line for every matching line
fh = open './file.txt'
while fh.gets
puts $_ if ~ /\b\w{2}\b/
end
;=> prints matching lines
A bit inconsistent?
gvim
10002 % ri IO.puts
= IO.puts
(from ruby core)
···
On Jan 18, 2014, at 11:47, gvim <gvimrc@gmail.com> wrote:
'print' seems to handle $_ differently 'puts':
fh = open './file.txt'
while fh.gets
print if ~ /\b\w{2}\b/
end
;=> prints matching lines
fh = open './file.txt'
while fh.gets
puts if ~ /\b\w{2}\b/
end
;=> prints a blank line for every matching line
fh = open './file.txt'
while fh.gets
puts $_ if ~ /\b\w{2}\b/
end
;=> prints matching lines
A bit inconsistent?
------------------------------------------------------------------------------
ios.puts(obj, ...) -> nil
------------------------------------------------------------------------------
Writes the given objects to ios as with IO#print. Writes a record
separator (typically a newline) after any that do not already end with a
newline sequence. If called with an array argument, writes each element on a
new line. ***If called without arguments, outputs a single record separator.***
Using implicit $_ is generally considered bad style.
abinoam
(Abinoam Praxedes Marques Jr.)
20 January 2014 16:18
3
Dear gvim,
I think this was the intended behavior.
Kernel#print
If no arguments are given, prints $_.
IO#puts
If called without arguments, outputs a single record separator.
Abinoam Jr.
···
On Sat, Jan 18, 2014 at 4:47 PM, gvim <gvimrc@gmail.com> wrote:
'print' seems to handle $_ differently 'puts':
fh = open './file.txt'
while fh.gets
print if ~ /\b\w{2}\b/
end
;=> prints matching lines
fh = open './file.txt'
while fh.gets
puts if ~ /\b\w{2}\b/
end
;=> prints a blank line for every matching line
fh = open './file.txt'
while fh.gets
puts $_ if ~ /\b\w{2}\b/
end
;=> prints matching lines
A bit inconsistent?
gvim