Created
October 21, 2015 04:15
-
-
Save simkessy/cc77bbc814f87e3f1c8f to your computer and use it in GitHub Desktop.
Trying to access instance variable from service class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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