# Deprecating RUBY\_VERSION\_CODE

**URL:** <https://www.ruby-forum.com/t/deprecating-ruby-version-code/113921>\
**Category:** Development\
**Created:** [September 6, 2007, 6:51am UTC](https://www.ruby-forum.com/t/deprecating-ruby-version-code/113921 "2007-09-06T06:51:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [September 6, 2007, 6:51am UTC](https://www.ruby-forum.com/t/deprecating-ruby-version-code/113921/1 "2007-09-06T06:51:54Z")

</div>

e$B$J$+$@$G$9!#e(B

[ruby-core:12068]e$B$G;W$$=P$7$?$N$G$9$,!"$a$s$I$/$5$$$N$Ge(Bdeve$B$K?6$je(B  
e$B$^$9!#e(B

At Tue, 3 Apr 2007 15:30:16 +0900,  
Yukihiro M. wrote in [ruby-core:10847]:

> |Furthermore, I’d rather want to remove RUBY\_VERSION\_CODE from  
> |version.h, and change RUBY\_VERSION object to a particular  
> |object from mere String.
> 
> It is arguable.

RUBY\_VERSIONe$B$re(BRuby::VersionNumbere$B$H$$$&%/%i%9$N%\*%V%8%’%/%H$K$7e(B  
e$B$F$\_$^$7$?!#:G=i$Oe(Bto\_stre$B$r;}$D$@$1$Ne(BStructe$B$K$7$h$&$+$H;W$C$?$s$Ge(B  
e$B$9$,!"e(Bgsube$B$J$I$,;H$o$l$F$$$?$N$GCf?H$O$=$N$^$^e(BStringe$B$K$7$F$7$^$$e(B  
e$B$^$7$?!#e(B

# Index: version.c

— version.c (revision 13347)  
+++ version.c (working copy)  
@@ -20,15 +20,90 @@ const char ruby\_platform[] = RUBY\_PLATFO  
const int ruby\_patchlevel = RUBY\_PATCHLEVEL;

+static VALUE  
+version\_init(VALUE self, VALUE major, VALUE minor, VALUE teeny)  
+{

- char buf[(sizeof(long)\*CHAR\_BIT/3+(sizeof(long)\*CHAR\_BIT\<80))\*3];
- 
- rb\_call\_super(0, 0);
- snprintf(buf, sizeof buf, “%u.%u.%u”, NUM2UINT(major),  
NUM2UINT(minor), NUM2UINT(teeny));
- rb\_str\_cat2(self, buf);
- rb\_iv\_set(self, “major”, major);
- rb\_iv\_set(self, “minor”, minor);
- rb\_iv\_set(self, “teeny”, teeny);
- OBJ\_FREEZE(self);
- return self;  
+}
- 

+#define version\_attr(n)   
+static VALUE version\_##n(VALUE self) {return rb\_attr\_get(self,  
rb\_intern(#n));}  
+  
+version\_attr(major)  
+version\_attr(minor)  
+version\_attr(teeny)  
+  
+static VALUE  
+version\_to\_a(VALUE self)  
+{

- return rb\_ary\_new3(3, version\_major(self), version\_minor(self),  
version\_teeny(self));  
+}
- 

+static VALUE  
+version\_cmp(VALUE self, VALUE other)  
+{

- VALUE tmp = rb\_check\_convert\_type(other, T\_ARRAY, “Array”, “to\_a”);
- long i;
- 
- if (NIL\_P(tmp)) {
- VALUE sep = rb\_const\_get(rb\_obj\_class(self), rb\_intern(“Separator”));
- tmp = rb\_ary\_to\_ary(rb\_funcall2(other, rb\_intern(“split”), 1, &sep));
- }
- other = rb\_ary\_new2(RARRAY\_LEN(tmp));
- for (i = 0; i \< RARRAY\_LEN(tmp); ++i) {
- VALUE e = rb\_Integer(rb\_ary\_entry(tmp, i));
- rb\_ary\_push(other, e);
- }
- 
- self = rb\_convert\_type(self, T\_ARRAY, “Array”, “to\_a”);
- return rb\_ary\_cmp(self, other);  
+}
- 

+static VALUE  
+ruby\_version\_number(VALUE mRuby)  
+{

- VALUE cVer = rb\_define\_class\_under(mRuby, “VersionNumber”,  
rb\_cString);
- 
- rb\_define\_method(cVer, “initialize”, version\_init, 3);
- rb\_define\_method(cVer, “to\_ary”, version\_to\_a, 0);
- rb\_define\_method(cVer, “to\_a”, version\_to\_a, 0);
- rb\_define\_method(cVer, “\<=\>”, version\_cmp, 1);
- rb\_define\_method(cVer, “major”, version\_major, 0);
- rb\_define\_method(cVer, “minor”, version\_minor, 0);
- rb\_define\_method(cVer, “teeny”, version\_teeny, 0);
- rb\_define\_const(cVer, “Separator”, rb\_reg\_new(rb\_str\_new("\.", 2),  
0));
- 
- return rb\_funcall(cVer, rb\_intern(“new”), 3,
- 

```
     INT2FIX(RUBY_VERSION_MAJOR),

```

- 

```
     INT2FIX(RUBY_VERSION_MINOR),

```

- 

```
     INT2FIX(RUBY_VERSION_TEENY));

```

+}  
+  
void  
Init\_version(void)  
{

- VALUE v = rb\_obj\_freeze(rb\_str\_new2(ruby\_version));  
+#define RUBY\_CONST(name, val) do { \

- static const char varname[] = name; \
- rb\_define\_const(mRuby, varname + 5, val); \
- rb\_define\_global\_const(varname, val); \
- } while (0)
- 
- VALUE mRuby = rb\_define\_module(“Ruby”);
- VALUE v = ruby\_version\_number(mRuby);  
VALUE d = rb\_obj\_freeze(rb\_str\_new2(ruby\_release\_date));  
VALUE p = rb\_obj\_freeze(rb\_str\_new2(ruby\_platform));

- rb\_define\_global\_const(“RUBY\_VERSION”, v);
- rb\_define\_global\_const(“RUBY\_RELEASE\_DATE”, d);
- rb\_define\_global\_const(“RUBY\_PLATFORM”, p);
- rb\_define\_global\_const(“RUBY\_PATCHLEVEL”,  
INT2FIX(RUBY\_PATCHLEVEL));

- RUBY\_CONST(“RUBY\_VERSION”, v);
- RUBY\_CONST(“RUBY\_RELEASE\_DATE”, d);
- RUBY\_CONST(“RUBY\_PLATFORM”, p);
- RUBY\_CONST(“RUBY\_PATCHLEVEL”, INT2FIX(RUBY\_PATCHLEVEL));  
}

---

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [September 7, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/deprecating-ruby-version-code/113921/2 "2007-09-07T18:44:20Z")

</div>

e$B$J$+$@$G$9!#e(B

At Thu, 6 Sep 2007 13:50:59 +0900,  
Nobuyoshi N. wrote in [ruby-dev:31743]:

> RUBY\_VERSIONe$B$re(BRuby::VersionNumbere$B$H$$$&%/%i%9$N%\*%V%8%’%/%H$K$7e(B  
> e$B$F$\_$^$7$?!#:G=i$Oe(Bto\_stre$B$r;}$D$@$1$Ne(BStructe$B$K$7$h$&$+$H;W$C$?$s$Ge(B  
> e$B$9$,!"e(Bgsube$B$J$I$,;H$o$l$F$$$?$N$GCf?H$O$=$N$^$^e(BStringe$B$K$7$F$7$^$$e(B  
> e$B$^$7$?!#e(B

to\_arye$B$de(Bto\_ae$B$rDj5A$7$F$$$k$He(B puts RUBY\_VERSION  
e$B$G$+$J$j;4GT$7$?e(B  
e$B5$J,$J$N$G!"e(Bto\_splate$B$r;H$&$h$&$K$7$F$\_$^$7$?!#e(B

e$B$7$+$7!“e(BRUBY\_VERSIONe$B$r$I$&$9$k$+$H$OJL$K!”$3$Ne(Bcheck\_splat()e$B$N$he(B  
e$B$&$J4X?t$ODs6!$7$F$$$k$H$J$K$+$HJXMx$N$h$&$J5$$,$9$k$N$G$9$,!#e(B

diff -U2 version.c version.c  
— version.c (working copy)  
+++ version.c (working copy)  
@@ -43,5 +43,5 @@

static VALUE  
-version\_to\_a(VALUE self)  
+version\_to\_splat(VALUE self)  
{  
return rb\_ary\_new3(3, version\_major(self), version\_minor(self),  
version\_teeny(self));  
@@ -49,12 +49,18 @@

static VALUE  
+check\_splat(VALUE ary)  
+{

- return rb\_check\_convert\_type(ary, T\_ARRAY, “Array”, “to\_splat”);  
+}
- 

+static VALUE  
version\_cmp(VALUE self, VALUE other)  
{

- VALUE tmp = rb\_check\_convert\_type(other, T\_ARRAY, “Array”, “to\_a”);

- VALUE tmp = check\_splat(other);  
long i;

- tmp = rb\_ary\_to\_ary(rb\_funcall2(other, rb\_intern(“split”), 1, &sep));

- tmp = check\_splat(rb\_funcall2(other, rb\_intern(“split”), 1, &sep));  
}  
other = rb\_ary\_new2(RARRAY\_LEN(tmp));  
@@ -64,5 +70,5 @@  
}

- self = rb\_convert\_type(self, T\_ARRAY, “Array”, “to\_a”);

- self = check\_splat(self);  
return rb\_ary\_cmp(self, other);  
}  
@@ -74,6 +80,5 @@

- rb\_define\_method(cVer, “to\_ary”, version\_to\_a, 0);
- rb\_define\_method(cVer, “to\_a”, version\_to\_a, 0);

- rb\_define\_method(cVer, “to\_splat”, version\_to\_splat, 0);  
rb\_define\_method(cVer, “\<=\>”, version\_cmp, 1);  
rb\_define\_method(cVer, “major”, version\_major, 0);
