From: Mike Stok Date: 2013-04-09T20:15:43+09:00 Subject: Re: Confusion with Forwarrordable#delegate - throwing an er What are you trying to do exactly? If you want to add a couple of delegations to an instance of MyQueue then maybe this is what you want to do: # ... your class definition def exercise(obj) puts "exercising #{obj}" puts obj.first obj.mypush 'foo' puts obj.first obj.clear puts obj.first end q1 = MyQueue.new class << q1 delegate [:clear, :first] => :@queue end q2 = MyQueue.new exercise q1 # should have first & clear methods delegated exercise q2 # should complain at the first call of first Hope this helps, Mike On 2013-04-07, at 2:50 AM, Love U Ruby wrote: > require 'forwardable' > > class MyQueue > > extend Forwardable > attr_reader :queue > > def initialize > @queue = [] > end > > def_delegator :@queue, :push, :mypush > > end > > q = MyQueue.new > > q.instance_delegate [:clear, :first] => @q > #`
': undefined method `instance_delegate' for # @queue=[]> (NoMethodError) > > q.delegate [:clear, :first] => @q > > #`
': undefined method `delegate' for # @queue=[]> (NoMethodError) > > > Can you tell me what wrong I did? How to fix that? > > -- > Posted via http://www.ruby-forum.com/. -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.