Βͳ͍͏ͪʹ͍ͬͯΔProc class ArticlesController < ApplicationController before_action -> do redirect_to root_path end def index # ॲཧ end end -> do redirect_to root_path end ͜ͷ෦Proc(lambda)
ՃॲཧBeforeAfter MiniMagick::Tool::Convert.new do |command| command << 'images/input.jpg' command.merge! %W[-rotate 90] command << 'images/output.jpg' end def execute MiniMagick::Tool::Convert.new(&build_command) end def args [input_path, rotate_arg, output_path] end def rotate_arg %w[-rotate 90] end ໋໊ʹΑΓ ԿΛ͢Δͷ͔ҰͰΘ͔Δ Before After
Method#to_procͷRuby࣮(̘࣮ͷίϝϯτ͔ΒҾ༻) class Method def to_proc lambda do |*_1| self.call(*_1) end end end શͯͷ ϒϩοΫҾΛ ࣮ߦ͢Δϝιουͷ Ҿʹల։ શͯͷ ϒϩοΫҾΛ splatͰྻʹ ϝιουΛ࣮ߦ
Symbol#to_procͷRuby࣮ class Symbol def to_proc proc do |_1, *_2| _1.method(self) .call(*_2) end end end ࠷ॳͷϒϩοΫҾ ͕Ϩγʔό &͖Ͱͨ͠ Symbolͷ໊લͷ ϝιουΛ࣮ߦ 2൪Ҏ߱ͷ ϒϩοΫҾ splatͰྻʹ 2൪Ҏ߱ͷ ϒϩοΫҾΛ ࣮ߦ͢Δϝιουͷ Ҿʹల։