Ruby の問題です。
以下のテストをパスするメソッド m
を定義せよ。
require "test/unit"
class T < Test::Unit::TestCase
test "" do
assert_equal 0, m{ |x| x }
assert_equal 1, m{ |x, y| x * y }
end
end
答えはここをめくってね
def m(&b)
yield b.arity == 1 ? 0 : [1, 1]
end
(追記)少し難しくした続編を書きました。
m(&->(x,y){x}) が 0 で m(&->(x,y){x*y}) が 1 だと? - Qiita