[#32676] VC++ embedded rubygems gives NoMethodError undefined method `synchronize' for Mutex — Phlip <phlip2005@...>
[I will try Bill Kelly's PDB path advice presently; this issue is more
5 messages
2010/10/03
[#32687] Re: VC++ embedded rubygems gives NoMethodError undefined method `synchronize' for Mutex
— Roger Pack <rogerdpack2@...>
2010/10/04
> This one's about...
[#32703] Re: VC++ embedded rubygems gives NoMethodError undefined method `synchronize' for Mutex
— Phlip <phlip2005@...>
2010/10/05
> > #<NoMethodError: undefined method `synchronize' for #<Mutex:0x750faa8>>
[#32698] [Ruby 1.9-Feature#3908][Open] private constant — Yusuke Endoh <redmine@...>
Feature #3908: private constant
10 messages
2010/10/05
[#32795] Call for Cooperation: CFUNC usage survey — SASADA Koichi <ko1@...>
Hi,
5 messages
2010/10/15
[#32814] WeakHash — Santiago Pastorino <santiago@...>
Hi guys,
6 messages
2010/10/15
[#32844] [Ruby 1.9-Feature#3963][Open] Map class in standard library — Thomas Sawyer <redmine@...>
Feature #3963: Map class in standard library
3 messages
2010/10/18
[#32864] [Ruby 1.9-Bug#3972][Open] r28668 breaks test/unit when combined with the testing rake task — Aaron Patterson <redmine@...>
Bug #3972: r28668 breaks test/unit when combined with the testing rake task
6 messages
2010/10/20
[#32932] Behavior of initialize in 1.9 — Aaron Patterson <aaron@...>
The behavior of initialize in 1.9 seems to have changed. Here is an irb
5 messages
2010/10/28
[#32960] [Ruby 1.9-Bug#4005][Open] YAML fails to roundtrip Time objects — Peter Weldon <redmine@...>
Bug #4005: YAML fails to roundtrip Time objects
6 messages
2010/10/29
[#32976] Improve MinGW builds for Ruby 1.8.7, 1.9.2 and 1.9.3 — Luis Lavena <luislavena@...>
Hello,
10 messages
2010/10/30
[#32978] Re: Improve MinGW builds for Ruby 1.8.7, 1.9.2 and 1.9.3
— Aaron Patterson <aaron@...>
2010/10/30
On Sun, Oct 31, 2010 at 03:42:02AM +0900, Luis Lavena wrote:
[ruby-core:32759] [Ruby 1.8-Bug#3938][Open] Ruby incorrectly compares the length of Array elements of Enumerable objects to the arity of Methods given as blocks to Enumerable methods
From:
Ethan - <redmine@...>
Date:
2010-10-12 18:21:27 UTC
List:
ruby-core #32759
Bug #3938: Ruby incorrectly compares the length of Array elements of Enumerable objects to the arity of Methods given as blocks to Enumerable methods
http://redmine.ruby-lang.org/issues/show/3938
Author: Ethan -
Status: Open, Priority: Normal
Category: core
ruby -v: ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0] (and others, see description)
Given an Enumerable object that has an element which is an Array, when an Enumerable method which takes a block (#map, #detect, etc) is called on that object and given a Method as its block, Ruby will incorrectly compare the length of the Array to the arity of the Method.
def Object.onearg(arg)
arg
end
amethod = Object.method(:onearg)
aproc = proc{|arg| arg}
amethod and aproc both have arity of 1. they should generally behave the same. but, they behave differently when given as a block to Enumerable methods, with amethod behaving incorrectly when the Enumerable in question contains an array:
>> [[1, 2]].detect(&amethod)
ArgumentError: wrong number of arguments (2 for 1)
this seems to incorrectly compare the length of the element [1, 2] to the arity of amethod, even though it's passing one argument (the array [1, 2]) to amethod.
the Proc behaves correctly:
>> [[1, 2]].detect(&aproc)
=> [1, 2]
this does not compare the element's length to the arity of aproc, and so works fine.
Giving the Method as a block works fine when the arity happens to be the same as the length of the element which is an array:
> [[1]].detect(&amethod)
=> [1]
Even though it is passed the whole array (seen in the return value), and not the element of the array.
File is attached to minimally reproduce, and its output is:
[1, 2]
[1]
methodarity.rb:10:in `onearg': wrong number of arguments (2 for 1) (ArgumentError)
from methodarity.rb:10:in `to_proc'
from methodarity.rb:7:in `detect'
from methodarity.rb:10:in `each'
from methodarity.rb:10:in `detect'
from methodarity.rb:10
Tested on:
ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]
ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin9.8.0]
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.8.0]
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin9.8.0]
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]
ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]
Behaves correctly in ruby 1.9.*.
----------------------------------------
http://redmine.ruby-lang.org
Attachments (1)
methodarity.rb
(347 Bytes, text/x-ruby-script)
def Object.onearg(arg)
arg
end
amethod = Object.method(:onearg)
aproc = proc{|arg| arg}
require 'pp'
pp([[1, 2]].detect(&aproc)) # works because proc works correctly
pp([[1]].detect(&amethod)) # works because arity happens to be the same as [1].size
pp([[1, 2]].detect(&amethod)) # doesn't work because arity isn't the asme as [1, 2].size