Skip to content

Commit a099e6e

Browse files
author
Michal Datberg
committed
Try method from rails to have a better compatibility
1 parent f2ac684 commit a099e6e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/grape-swagger.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,14 @@ class Object
140140
# @person ? @person.name : nil
141141
# vs
142142
# @person.try(:name)
143-
def try(method)
144-
send method if respond_to? method
143+
#
144+
# File activesupport/lib/active_support/core_ext/object/try.rb#L32
145+
def try(*a, &b)
146+
if a.empty? && block_given?
147+
yield self
148+
else
149+
__send__(*a, &b)
150+
end
145151
end
146152
end
147153

0 commit comments

Comments
 (0)