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:

  1. base.variable_name = []
  2. %x|#{base}.variable_name = []|
  3. base.instance_variable_set(:@variable_name,[])
  4. base.instance_exec{@variable_name = []}
  5. 1-2 inside of base.instance_exec using self instead of base

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

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -