Use Hash#fetch

This commit is contained in:
joker1007 2016-02-25 12:19:42 +09:00
parent fe7c377399
commit 880b0f8acf
1 changed files with 2 additions and 2 deletions

View File

@ -38,8 +38,8 @@ module Google
def getter_fn(name)
ivar_name = "@#{name}".to_sym
lambda do |_|
if respond_to?(:[])
self.key?(name) ? self[name] : instance_variable_get(ivar_name)
if respond_to?(:fetch)
fetch(name, instance_variable_get(ivar_name))
else
instance_variable_get(ivar_name)
end