저는 술어 인 Proc를 가지고 있습니다.루비에서 술어를 부정 처리합니다.
Proc.new { |number| number.even? }
어떻게 든 반대의 의미를 갖는 다른 Proc를 만드는 방법이 있습니까? 나는 Proc가 함수 매개 변수로 올 것이기 때문에 Proc의 "본문"을 변경할 수 없습니다.
def negate(proc)
negated proc with meaning opposite of this of proc
end
감사 :이 유사한 기능을한다고한다
not(Proc.new { |number| number.even? }
# which of course doesn't work :(
와 나는
Proc.new { |number| number.odd? }
아이디어로 동일한 작업을 수행 할 : 그래서 이런 걸 원하는 너는 대단히 사전에!
나에게 명확하지 않습니다. 아마 당신은 proc의 결과를 부정하려고합니다. 맞나요? –
네, 그 일을 할 것이라고 생각합니다. – Faery
실례 (22 번째 줄)는 http://rosettacode.org/wiki/Dinesman%27s_multiple-dwelling_problem#By_parsing_the_problem을 참조하십시오. – steenslag