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_ok(!iterator?)
|
||||
|
||||
def ttt
|
||||
test_ok(iterator?)
|
||||
end
|
||||
ttt{}
|
||||
|
||||
# yield at top level
|
||||
test_ok(!defined?(yield))
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module IRB
|
|||
class << self
|
||||
alias_method :exit, ExtendCommand.irb_original_method_name('exit')
|
||||
end
|
||||
if iterator?
|
||||
if block_given?
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
|
|
|
@ -263,7 +263,7 @@ class Shell
|
|||
def chdir(path = nil, verbose = @verbose)
|
||||
check_point
|
||||
|
||||
if iterator?
|
||||
if block_given?
|
||||
notify("chdir(with block) #{path}") if verbose
|
||||
cwd_old = @cwd
|
||||
begin
|
||||
|
@ -297,7 +297,7 @@ class Shell
|
|||
def pushdir(path = nil, verbose = @verbose)
|
||||
check_point
|
||||
|
||||
if iterator?
|
||||
if block_given?
|
||||
notify("pushdir(with block) #{path}") if verbose
|
||||
pushdir(path, nil)
|
||||
begin
|
||||
|
@ -446,7 +446,7 @@ class Shell
|
|||
_head = true
|
||||
STDERR.print opts.collect{|mes|
|
||||
mes = mes.dup
|
||||
yield mes if iterator?
|
||||
yield mes if block_given?
|
||||
if _head
|
||||
_head = false
|
||||
prefix + mes
|
||||
|
|
|
@ -343,7 +343,7 @@ class Shell
|
|||
# %pwd, %cwd -> @pwd
|
||||
def notify(*opts)
|
||||
Shell.notify(*opts) {|mes|
|
||||
yield mes if iterator?
|
||||
yield mes if block_given?
|
||||
|
||||
mes.gsub!("%pwd", "#{@cwd}")
|
||||
mes.gsub!("%cwd", "#{@cwd}")
|
||||
|
@ -437,7 +437,7 @@ class Shell
|
|||
ali = ali.id2name if ali.kind_of?(Symbol)
|
||||
command = command.id2name if command.kind_of?(Symbol)
|
||||
begin
|
||||
if iterator?
|
||||
if block_given?
|
||||
@alias_map[ali.intern] = proc
|
||||
|
||||
eval((d = %Q[def #{ali}(*opts)
|
||||
|
|
|
@ -147,7 +147,7 @@ class Shell
|
|||
# yorn: Boolean(@shell.debug? or @shell.verbose?)
|
||||
def notify(*opts)
|
||||
@shell.notify(*opts) do |mes|
|
||||
yield mes if iterator?
|
||||
yield mes if block_given?
|
||||
|
||||
mes.gsub!("%id", "#{@command}:##{@pid}")
|
||||
mes.gsub!("%name", "#{@command}")
|
||||
|
|
|
@ -12,17 +12,12 @@ class Array
|
|||
end
|
||||
|
||||
class TestIterator < Test::Unit::TestCase
|
||||
def ttt
|
||||
assert(iterator?)
|
||||
end
|
||||
|
||||
def test_iterator
|
||||
assert(!iterator?)
|
||||
|
||||
ttt{}
|
||||
|
||||
# yield at top level !! here's not toplevel
|
||||
assert(!defined?(yield))
|
||||
def test_yield_at_toplevel
|
||||
assert_separately([],"#{<<~"begin;"}\n#{<<~'end;'}")
|
||||
begin;
|
||||
assert(!block_given?)
|
||||
assert(!defined?(yield))
|
||||
end;
|
||||
end
|
||||
|
||||
def test_array
|
||||
|
|
Loading…
Add table
Reference in a new issue