Example:
require "fluent/plugin/output"
module Fluent::Plugin
class Outer < Fluent::Plugin::Output
@outer_var = "Hello from outer variable"
class Inner
def initialize()
puts "@outer_var", @outer_var # nil
log.info "Hello from inner initialize" # undefined local variable or method log
outer_method() # undefined method `outer_method' for #<Outer::Inner:0x00007fd2100452b0> (NoMethodError)
end
end # Inner
def initialize()
Inner.new()
log.info "Hello from outer initialize" # works
end
def outer_method
puts "Hello from outer method"
end
end # Outer
end # Fluent::Plugin
How can I make the outer variables and methods accessible to the inner class? Example here shows how inner/outer classes are defined but not how outer class may be accessed. I understand that the concept of inner/outer classes don't exists in Ruby, as per this answer. What is the best way use the Inner
and Outer
class while still being part of the output
module.