Issue #12671 has been updated by Charles Nutter.


JRuby implements Hash#to_proc as:

```ruby
class Hash
  def to_proc
    method(:[]).to_proc
  end
end
```

This allows us to present the proc as a lambda with correct arity:

```
$ jruby -e "pr = {}.to_proc; puts pr.arity; puts pr.lambda?"
1
true
```

It works for MRI too:

```
$ ruby23 -e "class Hash; def to_proc; method(:[]).to_proc; end; end; pr = {}.to_proc; puts pr.arity; puts pr.lambda?"
1
true
```

I think this is more representative of this proc's behavior. Can MRI do it this way?

----------------------------------------
Bug #12671: Hash#to_proc result is not a lambda, but enforces arity
https://bugs.ruby-lang.org/issues/12671#change-60076

* Author: Charles Nutter
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
```
 $ ruby23 -e 'pr = {foo:1}.to_proc; puts pr.lambda?; pr.call rescue puts $!; pr.call(1, 2) rescue puts $!'
false
wrong number of arguments (given 0, expected 1)
wrong number of arguments (given 2, expected 1)
```

I believe it should be marked as a lambda, since it enforces arity.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>