0

i have a file info.yml that has info like this

"email1@gmail.com":
      ame: "Paul"
      from: "VISA-PG-Credit Card Acquittal-"
      project: "001-Admin"
      entity: "01-HTW (Los Angeles)"

"email2@gmail.com"
     name: "Bill"
     from: "VISA-PG-Company"
     project: "005-Admin"
     entity: "01-HTW (Panama)"

Now I am trying to access this info from console. When i try this

>>INFO_CONFIG[:"email1@gmail.com"]["project"]

it gives me correct result as "001-Admin" But if i try this as

>>sender = "email1@gmail.com"

>>INFO_CONFIG[:sender]["project"]

It gives me following error:

NoMethodError: undefined method `[]' for nil:NilClass

What is wrong with my syntax?

user3691308
  • 13
  • 1
  • 3

2 Answers2

0

You should probably use to_sym like this:

INFO_CONFIG[sender.to_sym]["project"]

It seems to do what you want:

"email1@gmail.com".to_sym #=> :"email1@gmail.com"
Mischa
  • 42,876
  • 8
  • 99
  • 111
-1

You pass in the symbol :sender as the array key, but you want the email address (as a string) as the key:

sender = "email1@gmail.com"
INFO_CONFIG[sender]['project']
zwippie
  • 15,050
  • 3
  • 39
  • 54