Project

General

Profile

Actions

Bug #8359

closed

If p is a proc, p.call(x) can take a block, but p[x] cannot

Added by alexeymuranov (Alexey Muranov) almost 11 years ago. Updated almost 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.0.0
[ruby-core:54739]

Description

=begin
format = lambda { |l, s = '', &w|
l.map {|e| w ? w[e] : e}.join(s)
}

format.call([1, 2], "\n") {|c| "[ #{ c } ]"}

=> "[ 1 ]\n[ 2 ]"

format[[1, 2], "\n"] {|c| "[ #{ c } ]"}

=> SyntaxError: unexpected { arg, expecting end-of-input

=end

Updated by Anonymous almost 11 years ago

  • Status changed from Open to Rejected

=begin
You can pass a block to (({ #[] })) in two ways:

format[[1, 2], "\n", &proc {|c| "[ #{ c } ]"}]

or:

format.[]([1, 2], "\n") {|c| "[ #{ c } ]"}

=end

Updated by alexeymuranov (Alexey Muranov) almost 11 years ago

=begin
Ok, maybe this is not a bug report but a feature request. Is there a reason to not allow (({ p[x] do ...}))?
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0