mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Prefer block_given? to iterator?
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
17aeff3e77
commit
c20aae965e
6 changed files with 13 additions and 25 deletions
|
@ -984,13 +984,6 @@ test_ok($z == 0)
|
||||||
|
|
||||||
test_check "iterator"
|
test_check "iterator"
|
||||||
|
|
||||||
test_ok(!iterator?)
|
|
||||||
|
|
||||||
def ttt
|
|
||||||
test_ok(iterator?)
|
|
||||||
end
|
|
||||||
ttt{}
|
|
||||||
|
|
||||||
# yield at top level
|
# yield at top level
|
||||||
test_ok(!defined?(yield))
|
test_ok(!defined?(yield))
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ module IRB
|
||||||
class << self
|
class << self
|
||||||
alias_method :exit, ExtendCommand.irb_original_method_name('exit')
|
alias_method :exit, ExtendCommand.irb_original_method_name('exit')
|
||||||
end
|
end
|
||||||
if iterator?
|
if block_given?
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
|
|
|
@ -263,7 +263,7 @@ class Shell
|
||||||
def chdir(path = nil, verbose = @verbose)
|
def chdir(path = nil, verbose = @verbose)
|
||||||
check_point
|
check_point
|
||||||
|
|
||||||
if iterator?
|
if block_given?
|
||||||
notify("chdir(with block) #{path}") if verbose
|
notify("chdir(with block) #{path}") if verbose
|
||||||
cwd_old = @cwd
|
cwd_old = @cwd
|
||||||
begin
|
begin
|
||||||
|
@ -297,7 +297,7 @@ class Shell
|
||||||
def pushdir(path = nil, verbose = @verbose)
|
def pushdir(path = nil, verbose = @verbose)
|
||||||
check_point
|
check_point
|
||||||
|
|
||||||
if iterator?
|
if block_given?
|
||||||
notify("pushdir(with block) #{path}") if verbose
|
notify("pushdir(with block) #{path}") if verbose
|
||||||
pushdir(path, nil)
|
pushdir(path, nil)
|
||||||
begin
|
begin
|
||||||
|
@ -446,7 +446,7 @@ class Shell
|
||||||
_head = true
|
_head = true
|
||||||
STDERR.print opts.collect{|mes|
|
STDERR.print opts.collect{|mes|
|
||||||
mes = mes.dup
|
mes = mes.dup
|
||||||
yield mes if iterator?
|
yield mes if block_given?
|
||||||
if _head
|
if _head
|
||||||
_head = false
|
_head = false
|
||||||
prefix + mes
|
prefix + mes
|
||||||
|
|
|
@ -343,7 +343,7 @@ class Shell
|
||||||
# %pwd, %cwd -> @pwd
|
# %pwd, %cwd -> @pwd
|
||||||
def notify(*opts)
|
def notify(*opts)
|
||||||
Shell.notify(*opts) {|mes|
|
Shell.notify(*opts) {|mes|
|
||||||
yield mes if iterator?
|
yield mes if block_given?
|
||||||
|
|
||||||
mes.gsub!("%pwd", "#{@cwd}")
|
mes.gsub!("%pwd", "#{@cwd}")
|
||||||
mes.gsub!("%cwd", "#{@cwd}")
|
mes.gsub!("%cwd", "#{@cwd}")
|
||||||
|
@ -437,7 +437,7 @@ class Shell
|
||||||
ali = ali.id2name if ali.kind_of?(Symbol)
|
ali = ali.id2name if ali.kind_of?(Symbol)
|
||||||
command = command.id2name if command.kind_of?(Symbol)
|
command = command.id2name if command.kind_of?(Symbol)
|
||||||
begin
|
begin
|
||||||
if iterator?
|
if block_given?
|
||||||
@alias_map[ali.intern] = proc
|
@alias_map[ali.intern] = proc
|
||||||
|
|
||||||
eval((d = %Q[def #{ali}(*opts)
|
eval((d = %Q[def #{ali}(*opts)
|
||||||
|
|
|
@ -147,7 +147,7 @@ class Shell
|
||||||
# yorn: Boolean(@shell.debug? or @shell.verbose?)
|
# yorn: Boolean(@shell.debug? or @shell.verbose?)
|
||||||
def notify(*opts)
|
def notify(*opts)
|
||||||
@shell.notify(*opts) do |mes|
|
@shell.notify(*opts) do |mes|
|
||||||
yield mes if iterator?
|
yield mes if block_given?
|
||||||
|
|
||||||
mes.gsub!("%id", "#{@command}:##{@pid}")
|
mes.gsub!("%id", "#{@command}:##{@pid}")
|
||||||
mes.gsub!("%name", "#{@command}")
|
mes.gsub!("%name", "#{@command}")
|
||||||
|
|
|
@ -12,17 +12,12 @@ class Array
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestIterator < Test::Unit::TestCase
|
class TestIterator < Test::Unit::TestCase
|
||||||
def ttt
|
def test_yield_at_toplevel
|
||||||
assert(iterator?)
|
assert_separately([],"#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
end
|
begin;
|
||||||
|
assert(!block_given?)
|
||||||
def test_iterator
|
assert(!defined?(yield))
|
||||||
assert(!iterator?)
|
end;
|
||||||
|
|
||||||
ttt{}
|
|
||||||
|
|
||||||
# yield at top level !! here's not toplevel
|
|
||||||
assert(!defined?(yield))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_array
|
def test_array
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue