diff --git a/tools/buildgen/plugins/expand_version.py b/tools/buildgen/plugins/expand_version.py
index a103618c01add593ec08219804d8543442ab9060..b55e1b15ff8278c6b8c98c7764635a974882b1ab 100755
--- a/tools/buildgen/plugins/expand_version.py
+++ b/tools/buildgen/plugins/expand_version.py
@@ -51,6 +51,7 @@ LANGUAGES = [
 class Version:
 
   def __init__(self, s):
+    self.tag = None
     if '-' in s:
       s, self.tag = s.split('-')
     self.major, self.minor, self.patch = [int(x) for x in s.split('.')]
@@ -78,7 +79,10 @@ class Version:
 
   def ruby(self):
     """Version string in Ruby style"""
-    return '%d.%d.%d.%s' % (self.major, self.minor, self.patch, self.tag)
+    if self.tag:
+      return '%d.%d.%d.%s' % (self.major, self.minor, self.patch, self.tag)
+    else:
+      return '%d.%d.%d' % (self.major, self.minor, self.patch)
 
 def mako_plugin(dictionary):
   """Expand version numbers: