Use Hash#fetch
This commit is contained in:
parent
fe7c377399
commit
880b0f8acf
|
@ -38,8 +38,8 @@ module Google
|
||||||
def getter_fn(name)
|
def getter_fn(name)
|
||||||
ivar_name = "@#{name}".to_sym
|
ivar_name = "@#{name}".to_sym
|
||||||
lambda do |_|
|
lambda do |_|
|
||||||
if respond_to?(:[])
|
if respond_to?(:fetch)
|
||||||
self.key?(name) ? self[name] : instance_variable_get(ivar_name)
|
fetch(name, instance_variable_get(ivar_name))
|
||||||
else
|
else
|
||||||
instance_variable_get(ivar_name)
|
instance_variable_get(ivar_name)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue