Skip to content

Commit

Permalink
Merge pull request #88 from ddfreyne/argument-list-each-enumerator
Browse files Browse the repository at this point in the history
Let ArgumentList#each return enumerator unless block given
  • Loading branch information
denisdefreyne authored Jan 19, 2019
2 parents ea6b55e + 2298e0a commit 8b74c86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/cri/argument_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def [](key)
end

def each
return to_enum(__method__) unless block_given?

@arguments_array.each { |e| yield(e) }
self
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_argument_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_enum
assert_equal(%w[A B C], args.map(&:upcase))
end

def test_enum_without_block
args = Cri::ArgumentList.new(%w[a b c], false, [])

assert_equal(%w[A B C], args.each.map(&:upcase))
end

def test_no_method_error
args = Cri::ArgumentList.new(%w[a b c], false, [])

Expand Down

0 comments on commit 8b74c86

Please sign in to comment.