lundi 1 avril 2019

Ruby - Code someone explain the following code

I have the following piece of code in a library, Could someone explain what does the code ("#{k}=") means in the following piece of code?

 if respond_to?("#{k}=")
        public_send("#{k}=", v)
      else
        raise UnknownAttributeError.new(self, k)
      end

I understand respond_to is a default function in Ruby but there is no definition/explanation given for this syntax, please help us.

thanks.,
Harry

Aucun commentaire:

Enregistrer un commentaire