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 -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -