def_instance_delegator

def_instance_delegator(accessor, method, ali = method)
Instance Public methods

Define method as delegator instance method with an optional alias name ali. Method calls to ali will be delegated to accessor.method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class MyQueue
  extend Forwardable
  attr_reader :queue
  def initialize
    @queue = []
  end
 
  def_delegator :@queue, :push, :mypush
end
 
q = MyQueue.new
q.mypush 42
q.queue    #=> [42]
q.push 23  #=> NoMethodError

def_delegator

doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.