include Math
a = (:to_s).to_proc
puts a[123]
は"123"になるのに
b = (:sin).to_proc
puts b[1]
はエラーになります。
in `[]': private method `sin' called for 1:Fixnum (NoMethodError)
>|ruby|
class Array
def any_true
reduce method(:or), false
end
def all_true
reduce method(:and), true
end
private
def or(a,b)
a or b
end
def and(a,b)
a and b
end
end
||<
ありがとうございます。使えそうですね。
2013/09/23 02:02:20http://ruby.g.hatena.ne.jp/garyo/20130922/p4
関数を渡して積分するサンプルを作ろうと思ったときにsin()は元々関数なので
b=sin みたいな形で関数を引数とする関数に渡せるといいのにと思い質問しました。