ruby - Run method class within block -


how can use instance variables , method within block in ruby?

class foo   @var = "my var"   def meth()     "my method"   end    module.something |variable|     p @var    #=> undefined     p meth()  #=> undefined   end end 

i not sure understand context, might help:

class foo   def initialize     @var = "my var"   end   def meth()     "my method"   end   def fee     amodule.something |variable|       p @var       p meth()        p variable     end   end end  # test:  module amodule   def self.something     yield "bar"   end end  foo = foo.new foo.fee 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

excel vba - VBA Proxy auto-configuration for http requests -

php - phpWord - Tables with borders in headers/footers -