wweare
wweare

Reputation: 241

How via method I can change the attribute name?

I have a method defined as follow:

def foobar(arg)
  FactoryGirl.create(:user, arg: nil)
end

When i call foobar('email') or foobar('name') i want my method to return this FactoryGirl.create(:user, email: nil) or FactoryGirl.create(:user, name: nil) respectively

How can i do it?

Sorry for my bad English

Upvotes: 0

Views: 42

Answers (2)

Arup Rakshit
Arup Rakshit

Reputation: 118271

You can use interpolation too.

def foobar(arg)
  FactoryGirl.create(:user, :"#{arg}" => nil)
end

Upvotes: 1

Marek Lipka
Marek Lipka

Reputation: 51151

This should work:

def foobar(parameter)
  FactoryGirl.create(:user, parameter.to_sym => nil)
end

Upvotes: 2

Related Questions