Skip to content

Commit

Permalink
Prefer block_given? to iterator?
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jan 18, 2019
1 parent 17aeff3 commit c20aae9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
7 changes: 0 additions & 7 deletions basictest/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -984,13 +984,6 @@ def $x.default(k)

test_check "iterator"

test_ok(!iterator?)

def ttt
test_ok(iterator?)
end
ttt{}

# yield at top level
test_ok(!defined?(yield))

Expand Down
2 changes: 1 addition & 1 deletion lib/irb/cmd/fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def execute
class << self
alias_method :exit, ExtendCommand.irb_original_method_name('exit')
end
if iterator?
if block_given?
begin
yield
ensure
Expand Down
6 changes: 3 additions & 3 deletions lib/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def expand_path(path)
def chdir(path = nil, verbose = @verbose)
check_point

if iterator?
if block_given?
notify("chdir(with block) #{path}") if verbose
cwd_old = @cwd
begin
Expand Down Expand Up @@ -297,7 +297,7 @@ def chdir(path = nil, verbose = @verbose)
def pushdir(path = nil, verbose = @verbose)
check_point

if iterator?
if block_given?
notify("pushdir(with block) #{path}") if verbose
pushdir(path, nil)
begin
Expand Down Expand Up @@ -446,7 +446,7 @@ def self.notify(*opts)
_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
Expand Down
4 changes: 2 additions & 2 deletions lib/shell/command-processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def concat(*jobs)
# %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}")
Expand Down Expand Up @@ -437,7 +437,7 @@ def self.alias_command(ali, command, *opts)
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/shell/system-command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def each(rs = nil)
# 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}")
Expand Down
17 changes: 6 additions & 11 deletions test/ruby/test_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ def iter_test2
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
Expand Down

0 comments on commit c20aae9

Please sign in to comment.