aboutsummaryrefslogtreecommitdiffhomepage
path: root/ruby/lib
diff options
context:
space:
mode:
authorGravatar parker <parker@shundaojia.com>2017-11-06 12:18:12 +0800
committerGravatar parker <parker@shundaojia.com>2017-11-17 11:43:14 +0800
commit8695997eb5adb3c504c3615f0e6f3891a9b7ebde (patch)
tree21890635a98c360ce0465aeeb1e41a4f27a1277c /ruby/lib
parentbcda919ceeae8bd854c07a8300d8996ef52315db (diff)
Google::Protobuf::Struct can access a missing key (#3846)
Diffstat (limited to 'ruby/lib')
-rw-r--r--ruby/lib/google/protobuf/well_known_types.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/ruby/lib/google/protobuf/well_known_types.rb b/ruby/lib/google/protobuf/well_known_types.rb
index 921ddbc0..e85fac56 100644
--- a/ruby/lib/google/protobuf/well_known_types.rb
+++ b/ruby/lib/google/protobuf/well_known_types.rb
@@ -149,6 +149,8 @@ module Google
Struct.class_eval do
def [](key)
self.fields[key].to_ruby
+ rescue NoMethodError
+ nil
end
def []=(key, value)
@@ -170,6 +172,10 @@ module Google
hash.each { |key, val| ret[key] = val }
ret
end
+
+ def has_key?(key)
+ self.fields.has_key?(key)
+ end
end
ListValue.class_eval do