[前][次][番号順一覧][スレッド一覧]

ruby-changes:54650

From: nobu <ko1@a...>
Date: Fri, 18 Jan 2019 18:52:55 +0900 (JST)
Subject: [ruby-changes:54650] nobu:r66866 (trunk): Prefer block_given? to iterator?

nobu	2019-01-18 18:52:50 +0900 (Fri, 18 Jan 2019)

  New Revision: 66866

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66866

  Log:
    Prefer block_given? to iterator?

  Modified files:
    trunk/basictest/test.rb
    trunk/lib/irb/cmd/fork.rb
    trunk/lib/shell/command-processor.rb
    trunk/lib/shell/system-command.rb
    trunk/lib/shell.rb
    trunk/test/ruby/test_iterator.rb
Index: basictest/test.rb
===================================================================
--- basictest/test.rb	(revision 66865)
+++ basictest/test.rb	(revision 66866)
@@ -984,13 +984,6 @@ test_ok($z == 0) https://github.com/ruby/ruby/blob/trunk/basictest/test.rb#L984
 
 test_check "iterator"
 
-test_ok(!iterator?)
-
-def ttt
-  test_ok(iterator?)
-end
-ttt{}
-
 # yield at top level
 test_ok(!defined?(yield))
 
Index: lib/shell.rb
===================================================================
--- lib/shell.rb	(revision 66865)
+++ lib/shell.rb	(revision 66866)
@@ -263,7 +263,7 @@ class Shell https://github.com/ruby/ruby/blob/trunk/lib/shell.rb#L263
   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 https://github.com/ruby/ruby/blob/trunk/lib/shell.rb#L297
   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 https://github.com/ruby/ruby/blob/trunk/lib/shell.rb#L446
       _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
Index: lib/irb/cmd/fork.rb
===================================================================
--- lib/irb/cmd/fork.rb	(revision 66865)
+++ lib/irb/cmd/fork.rb	(revision 66866)
@@ -21,7 +21,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/fork.rb#L21
           class << self
             alias_method :exit, ExtendCommand.irb_original_method_name('exit')
           end
-          if iterator?
+          if block_given?
             begin
               yield
             ensure
Index: lib/shell/system-command.rb
===================================================================
--- lib/shell/system-command.rb	(revision 66865)
+++ lib/shell/system-command.rb	(revision 66866)
@@ -147,7 +147,7 @@ class Shell https://github.com/ruby/ruby/blob/trunk/lib/shell/system-command.rb#L147
     #    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}")
Index: lib/shell/command-processor.rb
===================================================================
--- lib/shell/command-processor.rb	(revision 66865)
+++ lib/shell/command-processor.rb	(revision 66866)
@@ -343,7 +343,7 @@ class Shell https://github.com/ruby/ruby/blob/trunk/lib/shell/command-processor.rb#L343
     # %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 https://github.com/ruby/ruby/blob/trunk/lib/shell/command-processor.rb#L437
       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)
Index: test/ruby/test_iterator.rb
===================================================================
--- test/ruby/test_iterator.rb	(revision 66865)
+++ test/ruby/test_iterator.rb	(revision 66866)
@@ -12,17 +12,12 @@ class Array https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iterator.rb#L12
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]