LoginSignup
1
0

More than 5 years have passed since last update.

Ruby の Symbol#to_proc に引数を渡す拡張

Posted at

ブログ記事からの転載です。

[1,2,16].map(&:to_s(16)) みたいにかきたいよねー』というやつ。

class Symbol
    def call *args, &block
        proc { |myself|
            myself.send self, *args, &block
        }
    end
end

p [1, 2, 16].map(&:to_s.(16))
# => ["1", "2", "10"]

#call を定義してこういう風に書くことはできるけどもさて。

[おまけ]

iolite を使用するとこういう風に書くことは出来ます。

require "iolite"

include Iolite::Placeholders

p [1, 2, 16].map(&arg1.to_s(16))
# => ["1", "2", "10"]

[元ネタ]

このあたり

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0