0

I am trying to print a value from an external source is like this

:Email=>[{:Type=>"Primary", :Value=>"[email protected]"}]

When I am using :

@user_profile.userprofile[:Email]

I am getting this value

[{:Type=>"Primary", :Value=>"[email protected]"}]

How can I get this value I have tried few things but no success yet

2 Answers 2

1

In your case @user_profile.userprofile[:Email][0][:Type] should return your value. Because email = [{:type=>"Primary", :value=>"[email protected]"}] is array contains [0] element Hash.

Note: Don't use capitalized key in hash.

Sign up to request clarification or add additional context in comments.

Comments

0
@user_profile.userprofile[:Email][0][:Value]

2 Comments

Will you please explain this stuff [0]
@user2480754 @user_profile.userprofile[:Email] returns a array with one object in it. Since we want the first index of that array. We get it by using [0] where 0 is the number of the index. Index always starts counting at 0, then 1,2,3 etc.

Your Answer

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