You are mixing an instance and a class method in your example.
If this is really what you want, then you have to define an accessor with attr_reader
:
class Test
def initialize(params)
@has_test = params[:has_test]
@limit_test = params[:limit_test]
end
attr_reader :has_test
attr_reader :limit_test
def self.method1(params)
obj = Test.new(params)
p obj.has_test
p obj.limit_test
end
end
Test.method1(has_test: 1, limit_test: 3)
It the instance/class-method is a mistake, then this example may help you:
class Test
def initialize(params)
@has_test = params[:has_test]
@limit_test = params[:limit_test]
end
def method1()
p @has_test
p @limit_test
end
end
obj = Test.new(has_test: 1, limit_test: 3)
obj.method1
If you define also the accessors like in the first code, then you have again access from outside the class.
Just in case you don't want a reader, see also Access instance variable from outside the class