エントリーの編集
エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
Can you supply arguments to the map(&:method) syntax in Ruby?
記事へのコメント0件
- 注目コメント
- 新着コメント
このエントリーにコメントしてみましょう。
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています
- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
Can you supply arguments to the map(&:method) syntax in Ruby?
You can create a simple patch on Symbol like this: class Symbol def with(*args, &block) ->(caller... You can create a simple patch on Symbol like this: class Symbol def with(*args, &block) ->(caller, *rest) { caller.send(self, *rest, *args, &block) } end end Which will enable you to do not only this: a = [1,3,5,7,9] a.map(&:+.with(2)) # => [3, 5, 7, 9, 11] But also a lot of other cool stuff, like passing multiple parameters: arr = ["abc", "babc", "great", "fruit"] arr.map(&:center.with(20, '*'))