ruby - Can't create variable on base object in 'self.included' hook in Opal -
it's question title says, have included hook in module:
def self.included(base) puts 'included' base.extend api end
my api requires variables on object exists none of them being created.
i've tried:
base.variable_name = []
%x|#{base}.variable_name = []|
base.instance_variable_set(:@variable_name,[])
base.instance_exec{@variable_name = []}
- 1-2 inside of
base.instance_exec
usingself
instead ofbase
yet none of them work, console complains variable_name=
doesn't exist.
what.the.hell?
how variable exist on base object inside of included
hook?
in end, had use @variable_name ||= []
inside of function definitions work, don't works.
if want know why don't it's because defining object attributes in once places means can find they're defined , change initial value, whereas here have track down change (not hard it's principle).
personal preference guess.
Comments
Post a Comment