18

I'm trying to call a method on an ActiveRecord object where there is an attribute of the same name. This results in a SystemStackError: stack level too deep error.

How can I access the object attribute from within the method in order to modify it?

def first_name

 return self.first_name.upper

end
1
  • 2
    You could probably also do super.upper Commented Aug 14, 2018 at 14:04

1 Answer 1

39

If this is an Active Record model you can use read_attribute method

def first_name
  read_attribute(:first_name).upper
end
Sign up to request clarification or add additional context in comments.

1 Comment

or self[:first_name].upper if rubocop complains :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.