Reputation: 241
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
Reputation: 118271
You can use interpolation too.
def foobar(arg)
FactoryGirl.create(:user, :"#{arg}" => nil)
end
Upvotes: 1
Reputation: 51151
This should work:
def foobar(parameter)
FactoryGirl.create(:user, parameter.to_sym => nil)
end
Upvotes: 2