Integer#ord for 1.8

1.9 e$B$He(B 1.8 e$B$NN>J}$Ge(B ?a.ord e$B$Ge(B 97
e$B$,F@$i$l$k$h$&$K!"e(B1.8 e$B$Ke(B
Integer#ord e$B$r2C$($k$N$O$I$&$G$7$g$&$+!#e(B

Index: numeric.c

— numeric.c (e$B%j%S%8%g%se(B 13873)
+++ numeric.c (e$B:n6H%3%T!<e(B)
@@ -1807,6 +1807,27 @@
return rb_str_new(&c, 1);
}

+/*

    • call-seq:
    • int.ord    => int
      
    • Returns the int itself.
    • 65.ord    #=> 65
      
    • ?a.ord    #=> 97
      
    • 230.ord   #=> 230
      
    • This method is intended for compatibility to
    • character constant in Ruby 1.9.
  • */

+static VALUE
+int_ord(num)

  • VALUE num;
    +{
  • return num;
    +}

/********************************************************************
*

  • Document-class: Fixnum
    @@ -2924,6 +2945,7 @@
    rb_define_method(rb_cInteger, “succ”, int_succ, 0);
    rb_define_method(rb_cInteger, “next”, int_succ, 0);
    rb_define_method(rb_cInteger, “chr”, int_chr, 0);
  • rb_define_method(rb_cInteger, “ord”, int_ord, 0);
    rb_define_method(rb_cInteger, “to_i”, int_to_i, 0);
    rb_define_method(rb_cInteger, “to_int”, int_to_i, 0);
    rb_define_method(rb_cInteger, “floor”, int_to_i, 0);

At Sun, 11 Nov 2007 06:20:09 +0900,
Tanaka A. wrote:

1.9 と 1.8 の両方で ?a.ord で 97 が得られるように、1.8 に
Integer#ord ã‚’åŠ ãˆã‚‹ã®ã¯ã©ã†ã§ã—ã‚‡ã†ã‹ã€‚
"
String#ord ã‚’è¿½åŠ ã—ã¦ã©ã¡ã‚‰ã§ã‚‚ ‘a’.ord というのではいまいち
ですかね。?a.ord と書きたい気持ちの方が強いかな。


/
/__ __ Akinori.org / MUSHA.org
/ ) ) ) ) / FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp

“Different eyes see different things,
Different hearts beat on different strings –
But there are times for you and me when all such things agree”

At Mon, 12 Nov 2007 23:37:44 +0900,
Tanaka A. wrote:

In article [email protected],
“Akinori MUSHA” [email protected] writes:

String#ord ã‚’è¿½åŠ ã—ã¦ã©ã¡ã‚‰ã§ã‚‚ ‘a’.ord というのではいまいち
ですかね。?a.ord と書きたい気持ちの方が強いかな。

?a.ord のように ?a が書いてあるところを書き換えられるのであ
ればいいのですが、ライブラリの呼出元に ?a と書いてあって、ラ
イブラリ側でそれをサポートしたいというケースではうまくいきま
せん。

 なるほど。互換性のためだけというところが少し引っかかったん
ですが、少なくとも自然数なら意味は通る(ordinal:序数)ので納得
しました。


/
/__ __ Akinori.org / MUSHA.org
/ ) ) ) ) / FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp

“Different eyes see different things,
Different hearts beat on different strings –
But there are times for you and me when all such things agree”

In article [email protected],
“Akinori MUSHA” [email protected] writes:

String#ord e$B$rDI2C$7$F$I$A$i$G$be(B ‘a’.ord e$B$H$$$&$N$G$O$$$^$$$Ae(B
e$B$G$9$+$M!#e(B?a.ord e$B$H=q$-$?$$5$;}$A$NJ}$,6/$$$+$J!#e(B

?a.ord e$B$N$h$&$Ke(B ?a e$B$,=q$$$F$“$k$H$3$m$r=q$-49$($i$l$k$N$G$“e(B
e$B$l$P$$$$$N$G$9$,!”%i%$%V%i%j$N8F=P85$Ke(B ?a e$B$H=q$$$F$”$C$F!"%ie(B
e$B%$%V%i%jB&$G$=$l$r%5%]!<%H$7$?$$$H$$$&%1!<%9$G$O$&$^$/$$$-$^e(B
e$B$;$s!#e(B

e$B8D?ME*$K$$$($Pe(B abnf e$BFbIt$Ne(B natset (e$B<+A3?t$N=89ge(B)
e$B$,$=$&$G!“e(B
NatSet.new(?\n) e$B$J$I$H=q$-$?$$$H$$$&7P83$,$”$j$^$9!#$^$!!“e(B
natset e$B$Oe(B abnf e$B$NFbItE*$J$b$N$H$9$l$P8F=P85$r$9$Y$F=q$-49$(e(B
e$B$l$P$$$$$H$$$&$N$b$?$7$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