From: Charles Oliver Nutter Date: 2010-01-25T22:10:33+09:00 Subject: Re: Class variable inside block of defining instance method Ruby doesn't scope quite like that normally, but you can do it using instance_eval and define_method: def initialize(server1, server2) @echo = echo = IRC::Client.new(*server1) @listen = IRC::Client.new(*server2) @echo.instance_eval do define_method :message_received do |nick, channel, message, *args| if channel == "#Pre" echo.puts("PRIVMSG #{echo.channel} :#{message}") end end end end instance_eval has some quirks, and define_method methods are never as fast as normal methods (since they have full block dispatch semantics), but this should do what you need. - Charlie On Sun, Jan 24, 2010 at 3:13 AM, Mikkel Kroman wrote: > Hello. > > How do I perform something like this? > https://gist.github.com/6a2aa7e86cad8717541f > > It's the @echo variable inside the block I'm talking about, how do I > gain "access" to it? > > Sincerely, > phora. > -- > Posted via http://www.ruby-forum.com/. > >