Topic: Ruby idiom to safe gaurd against method calls to nil

I seem to recall reading somewhere that there's an idiom for this?

if @current_user && @current_user.admin?

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?

Re: Ruby idiom to safe gaurd against method calls to nil

Nevermind. I remembered (19:00) that

@current_user && @current_user.admin?

is the idiom for

if @current_user
  @current_user.admin?
end

This is because && is short-circuited at the first false, so @current_user.admin? never gets called if @current_user returns nil

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?