"Yukihiro Matsumoto" <matz / ruby-lang.org> schrieb im Newsbeitrag news:1045775864.869816.25765.nullmailer / picachu.netlab.jp... > Hi, > > In message "proc {} vs. Method#to_proc" > on 03/02/21, dblack / candle.superlink.net <dblack / candle.superlink.net> writes: > > |Proc objects created by Method#to_proc seem to care about their arity > |in a way that other Proc objects don't. > > Method#to_proc returns a Proc defined like > > Proc{|*args| self.call(*args)} > > this explains the behavior. While we're at it... I did a little testing and two things strike me odd: irb(main):143:0* RUBY_VERSION => "1.6.8" irb(main):144:0> procs = [ irb(main):145:1* Proc.new{|a| p a}, irb(main):146:1* Proc.new{|*a| p a}, irb(main):147:1* Proc.new{|a,| p a}, irb(main):148:1* Proc.new{|a,b| p a} irb(main):149:1> ] => [#<Proc:0x27dda90>, #<Proc:0x27dda60>, #<Proc:0x27dda30>, #<Proc:0x27dda00>] irb(main):150:0> procs.each_with_index{|p,i| puts "proc[#{i}].arity = #{p.arity} "} proc[0].arity = -1 proc[1].arity = -1 proc[2].arity = 1 proc[3].arity = 2 => [#<Proc:0x27dda90>, #<Proc:0x27dda60>, #<Proc:0x27dda30>, #<Proc:0x27dda00>] irb(main):151:0> procs.each_with_index{|p,i| puts "proc[#{i}]" irb(main):152:1> begin irb(main):153:2* p.call(i) irb(main):154:2> rescue irb(main):155:2> puts "ERROR" irb(main):156:2> end irb(main):157:1> } proc[0] 0 proc[1] [1] proc[2] 2 proc[3] ERROR => [#<Proc:0x27dda90>, #<Proc:0x27dda60>, #<Proc:0x27dda30>, #<Proc:0x27dda00>] irb(main):158:0> 1) Why is it that "proc[0].arity = -1"? Or put differently: To me it seems there is an asymmetry between proc[0].arity = proc[1].arity and the behavior of proc[0] that resembles more p[2]. If "proc[0].arity = 1" I would be fine, but -1 puzzles me... 2) Why does this parse "Proc.new{|a,| p a}"? (the comma with following bar) Thanks! robert