avoid #respond_to? in Cache.id_for

This commit is contained in:
http://jneen.net/ 2017-07-17 10:43:55 -07:00
parent e515aa548c
commit 45e9d28791
1 changed files with 8 additions and 5 deletions

View File

@ -21,11 +21,14 @@ module DeclarativePolicy
private
def id_for(obj)
if obj.respond_to?(:id) && obj.id
obj.id.to_s
else
"##{obj.object_id}"
end
id =
begin
obj.id
rescue NoMethodError
nil
end
id || "##{obj.object_id}"
end
end
end