Ruby 2.3.0 リファレンスマニュアル > ライブラリ一覧 > forwardableライブラリ > Forwardableモジュール > delegate
instance_delegate(hash) -> ()[permalink][rdoc]delegate(hash) -> ()メソッドの委譲先を設定します。
例:
require 'forwardable'
class Zap
extend Forwardable
delegate :length => :@str
delegate [:first, :last] => :@arr
def initialize
@arr = %w/foo bar baz/
@str = "world"
end
end
zap = Zap.new
zap.length # => 5
zap.first # => "foo"
zap.last # => "baz"