[#11357] [PATCH] an analogue of `long long' — "Nobuyoshi.Nakada" <nobu.nakada@...>

なかだです。

18 messages 2000/11/01
[#11358] Re: [PATCH] an analogue of `long long' — matz@... (Yukihiro Matsumoto) 2000/11/01

まつもと ゆきひろです

[#11364] Re: [PATCH] an analogue of `long long' — EGUCHI Osamu <eguchi@...> 2000/11/02

えぐち@エスアンドイー です。

[#11440] class Character (was: Ruby I18N) — Yasushi Shoji <yashi@...>

[ruby-dev:11428] からの続きですが、threadは切りました。

14 messages 2000/11/08
[#11442] Re: class Character (was: Ruby I18N) — TAKAHASHI Masayoshi <maki@...> 2000/11/08

高橋征義です。用語について。

[#11443] Re: class Character (was: Ruby I18N) — Yasushi Shoji <yashi@...> 2000/11/08

At Wed, 8 Nov 2000 20:44:55 +0900,

[#11520] A problem of Socket methods on Windows — OKA Toshiyuki <oka@...>

岡と申します。

22 messages 2000/11/15
[#11523] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11528] Re: A problem of Socket methods on Windows — matz@... (Yukihiro Matsumoto) 2000/11/15

まつもと ゆきひろです

[#11532] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11534] Re: A problem of Socket methods on Windows — OKA Toshiyuki <oka@...> 2000/11/15

岡です。

[#11535] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11538] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11662] IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org>

In article <E140cR3-0002ls-00@ev.netlab.zetabits.co.jp>,

22 messages 2000/11/28
[#11663] Re: IO (Re: fork problem?) — matz@... (Yukihiro Matsumoto) 2000/11/28

まつもと ゆきひろです

[#11664] Re: IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org> 2000/11/28

In article <E140fxW-0002u9-00@ev.netlab.zetabits.co.jp>,

[#11665] Re: IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org> 2000/11/28

In article <hvor93w5wb8.fsf@coulee.m17n.org>,

[#11669] Re: IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org> 2000/11/29

In article <hvoofz05uwz.fsf@coulee.m17n.org>,

[#11672] Re: IO (Re: fork problem?) — matz@... (Yukihiro Matsumoto) 2000/11/29

まつもと ゆきひろです

[#11675] Re: IO (Re: fork problem?) — Koji Arai <JCA02266@...> 2000/11/30

新井です。

[#11677] Re: IO (Re: fork problem?) — matz@... (Yukihiro Matsumoto) 2000/12/01

まつもと ゆきひろです

[ruby-dev:11516] Re: Ruby I18N

From: Kazuhiro NISHIYAMA <zn@...>
Date: 2000-11-14 15:27:25 UTC
List: ruby-dev #11516
On Fri, 10 Nov 2000 00:20:54 +0900
"  たけ  \(tk\)" <ggb03124@nifty.ne.jp> wrote:
>  しかし、次のようにやるとうまくいかないはず。String クラスのリテラルの
> 引数は、その時点でコンバートしたい。どうやるんでしょうか?。
> 
> 	str1 = String::MyString.new( 'abc' )
>
>  * initialize でコンバートしてはいけない。new の引数はそのまま取り込
> まれる。new の引数は String::MyString にコンバートすみのものでなければな
> らない。結局 str1 = 'abc'.convert_to String::MyString としたほうがよい。
> となるのかな?。でも、ついうっかりやってしまいそうな気がするなぁ。

うまくサンプルを書けませんでしたが、

String#convert_to(s)     Precision#prec(c)相当
String::convert_from(s)  Numeric::induced_from(num)相当

に対応させるようなモデルはどうでしょうか?

一般的にはMyString::convert_fromのように何か変換用のメソッドを
用意してそこだけで変換すればよさそうな気がします。

# 高速化したければ+とかも定義すればいいだけだし。


class String
  def convert_to klass
    return self if self.type == klass
    return klass.new(self)
  end
end

class String
  class MyString < String
    def initialize s
      self.replace MyString.convert_from s
      self
    end
  end

  def MyString.convert_from(s)
    s + "("+s.class.name+"->"+self.name+")"
  end
end

class String
  class YourString < String
    def initialize s
      self.replace YourString.convert_from s
      self
    end
  end

  def YourString.convert_from(s)
    s + "("+s.class.name+"->"+self.name+")"
  end
end

str1 = String::MyString.new( 'abc' )
str2 =  str1.convert_to String::YourString

p str1.type             ##  String::MyString
p str2.type             ##  String::YourString

p str1      ##  "abc(String->String::MyString)"
p str2      ##  "abc(String->String::MyString)(..MyString->..YourString)"


--- 
ZnZ(ゼット エヌ ゼット)
西山和広(Kazuhiro NISHIYAMA)
mailto:zn@mbf.nifty.com


In This Thread