Skip to content

Instantly share code, notes, and snippets.

@simkessy
Created October 21, 2015 04:15
Show Gist options
  • Save simkessy/cc77bbc814f87e3f1c8f to your computer and use it in GitHub Desktop.
Save simkessy/cc77bbc814f87e3f1c8f to your computer and use it in GitHub Desktop.
Trying to access instance variable from service class
class MyService
def initialize user, card, pricing_service
@user = user
end
end
# Initialize
MyService.new(current_user)
# Trying to return value outside controller, maybe in the console for example
x = MyService.new(User.first)???
x.instance_variables #returns an array containing [[0] :@user]
# is there a way to actually get that record?
# What I tried
x[@user]
x[:user]
x["user"]
x[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment