Getting NoMethodError ---> undefined method `[]' for nil:NilClass

142 Views Asked by At

I am totally new to Ruby and while testing some changes , I'm getting the error below: Can somebody please highlight what does the below mean ?

undefined method [] for nil:NilClass

adapterClient = Service.get_client(
      ADAPTER_SERVICE_NAME,
      service_info['server'],
      service_info['port'],
      service_info['path']
    )
1

There are 1 best solutions below

0
Roshan On

When you see undefined method '[]' for nil:NilClass, it means:

Hey! You have a value that is nil followed by [...], but nil doesn't have this method.

In your case, it could be service_info['server'], service_info['port'] or service_info['path'] is nil.