diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-18 09:52:50 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-18 09:52:50 +0000 |
commit | c20aae965e2e79fcf4c443b266f7012157d5b23b (patch) | |
tree | 3b1e6cbcd51d732d05bfd3273c0024c8a9658369 | |
parent | 17aeff3e77e6fe0d37a9943dd93bcb16c4bb9f66 (diff) |
Prefer block_given? to iterator?
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rwxr-xr-x | basictest/test.rb | 7 | ||||
-rw-r--r-- | lib/irb/cmd/fork.rb | 2 | ||||
-rw-r--r-- | lib/shell.rb | 6 | ||||
-rw-r--r-- | lib/shell/command-processor.rb | 4 | ||||
-rw-r--r-- | lib/shell/system-command.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_iterator.rb | 17 |
6 files changed, 13 insertions, 25 deletions
diff --git a/basictest/test.rb b/basictest/test.rb index 25d52ca1ef..5760a139b8 100755 --- a/basictest/test.rb +++ b/basictest/test.rb @@ -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)) diff --git a/lib/irb/cmd/fork.rb b/lib/irb/cmd/fork.rb index ae4d51b5d1..31d53dcaba 100644 --- a/lib/irb/cmd/fork.rb +++ b/lib/irb/cmd/fork.rb @@ -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 diff --git a/lib/shell.rb b/lib/shell.rb index 77b3b97ed3..095889626a 100644 --- a/lib/shell.rb +++ b/lib/shell.rb @@ -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 diff --git a/lib/shell/command-processor.rb b/lib/shell/command-processor.rb index 00357e06fd..5fe6056560 100644 --- a/lib/shell/command-processor.rb +++ b/lib/shell/command-processor.rb @@ -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) diff --git a/lib/shell/system-command.rb b/lib/shell/system-command.rb index 767a9ee12c..9d1b07e98c 100644 --- a/lib/shell/system-command.rb +++ b/lib/shell/system-command.rb @@ -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}") diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index ebfb60354a..54c095338f 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -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 |