I have a class with a private method:
class MyClass
attr_accessor :my_attr
def some_mth?(num)
# I want to use my_attr as a variale @myattr here
#and here i want to check if arr include num
@myattr.include?(num)
end
private
def some_pvt_mth
@myattr = [1,2,3,4]
for example generation array here
end
end
When I call @myattr inside some_mth, my variable @myattr is nil
How to use variable @myatt inside class, in every method is it possible?
How do I do it properly?
You have to define the instance variable value first: