以下の内容はhttps://tbpgr.hatenablog.com/entry/20120426/1335464793より取得しました。


Ruby応用 | 高階関数

パンくず

Ruby応用
高階関数

概要

高階関数について

高階関数とは

関数を引数にしたり、あるいは関数を戻り値とするような関数

サンプル

# 関数を返す関数
def get_method(method_name)
  method =<<"EOS"
def #{method_name}(message)
  puts message
end
EOS
  return eval(method)
end

my_method = get_method("my_method")

# 関数を引数にとる関数
def set_method(method, message)
  method.my_method message
end

set_method(my_method, "set_method test")

結果

set_method test



以上の内容はhttps://tbpgr.hatenablog.com/entry/20120426/1335464793より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14