Project

General

Profile

Bug #13202

Enumerable#slice_before does not take both argument and block at the same time, as it ought to.

Added by shyouhei (Shyouhei Urabe) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-02-02 trunk 57498) [x86_64-darwin15]
[ruby-core:79485]

Description

Both RDoc and Rurema have descriptions of Enumerable#slice_before with this example:

# split mails in mbox (slice before Unix From line after an empty line)
open("mbox") { |f|
  f.slice_before(emp: true) { |line, h|
    prevemp = h[:emp]
    h[:emp] = line == "\n"
    prevemp && line.start_with?("From ")
  }.each { |mail|
    mail.pop if mail.last == "\n"
    pp mail
  }
}

which doesn't work.

zsh % ruby -v tmp.rb
ruby 2.5.0dev (2017-02-02 trunk 57498) [x86_64-darwin15]
tmp.rb:3:in `slice_before': wrong number of arguments (given 1, expected 0) (ArgumentError)
        from tmp.rb:3:in `block in <main>'
        from tmp.rb:2:in `open'
        from tmp.rb:2:in `<main>'

Related issues

Related to Ruby master - Feature #10958: remove "initial_state" argument of Enumerable#{slice_before,chunk}Closed03/10/2015Actions
#1

Updated by naruse (Yui NARUSE) over 3 years ago

  • Related to Feature #10958: remove "initial_state" argument of Enumerable#{slice_before,chunk} added
#2

Updated by akr (Akira Tanaka) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset r57584.


[DOC] Update an obsolete example for slice_before.

The argument for Enumerable#slice_before is is removed at Ruby 2.3.

Reported by Shyouhei Urabe. [Bug #13202]

Updated by naruse (Yui NARUSE) over 3 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE

ruby_2_4 r57905 merged revision(s) 57584.

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE
#5

Updated by usa (Usaku NAKAMURA) over 3 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: DONTNEED, 2.3: REQUIRED, 2.4: DONE

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 2.2: DONTNEED, 2.3: REQUIRED, 2.4: DONE to 2.2: DONTNEED, 2.3: DONE, 2.4: DONE

ruby_2_3 r58155 merged revision(s) 57584.

Also available in: Atom PDF