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
Post a Comment