[#6862] Re: http_get.rb — 青山 和光 <PXN11625@...>

In-Reply-To: [ruby-list:6844] Re: http_get.rb

15 messages 1998/03/01

[#6906] ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...>

藤本です、こんにちは。

25 messages 1998/03/03
[#6907] Re: ruby's Icon ? — matz@... (Yukihiro Matsumoto) 1998/03/03

まつもと ゆきひろです

[#6908] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんにちは。

[#6911] Re: ruby's Icon ? — OZAWA Sakuro <ozawa@...> 1998/03/03

小澤さくです。

[#6912] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんにちは。

[#6914] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんばんは。

[#6918] manual 1.18b index — WATANABE Tetsuya <tetsu@...>

ruby-man-1.1b8 で、name タグがついているものを拾い集めて

17 messages 1998/03/04
[#6921] Re: manual 1.18b index — matz@... (Yukihiro Matsumoto) 1998/03/04

まつもと ゆきひろです

[#6954] Re: ruby's Icon ? — nosuzuki@... (Norio Suzuki)

こんばんは。鈴木教郎です。

18 messages 1998/03/04
[#6964] Re: ruby's Icon ? — matz@... (Yukihiro Matsumoto) 1998/03/05

まつもと ゆきひろです

[#7023] infinity — Tadayoshi Funaba <tadf@...>

ふなばです。

41 messages 1998/03/09
[#7029] Re: infinity — shugo@... (Shugo Maeda) 1998/03/09

前田です。

[#7033] Re: infinity — keiju@... (石塚圭樹 ) 1998/03/09

けいじゅ@日本ラショナルソフトウェアです.

[#7041] Re: infinity — Kazuhisa YANAGAWA <katze@...> 1998/03/10

In message <199803091741.CAA05774.keiju@cupmail0.rational.com>

[#7048] Re: infinity — keiju@... (Keiju ISHITSUKA) 1998/03/10

けいじゅ@日本ラショナルソフトウェアです.

[#7049] Re: infinity — matz@... (Yukihiro Matsumoto) 1998/03/10

まつもと ゆきひろです

[#7051] Re: infinity — keiju@... (石塚圭樹 ) 1998/03/10

けいじゅ@日本ラショナルソフトウェアです.

[#7054] Re: infinity — matz@... (Yukihiro Matsumoto) 1998/03/10

まつもと ゆきひろです

[#7050] Re: infinity — Kazuhisa YANAGAWA <katze@...> 1998/03/10

In message <199803100359.MAA08628.keiju@cupmail0.rational.com>

[#7259] Socket#shutdown — keiju@... (Keiju ISHITSUKA)

けいじゅ@日本ラショナルソフトウェアです.

16 messages 1998/03/28
[#7260] Re: Socket#shutdown — matz@... (Yukihiro Matsumoto) 1998/03/28

まつもと ゆきひろです

[#7265] Re: Socket#shutdown — keiju@... (石塚圭樹 ) 1998/03/29

けいじゅ@日本ラショナルソフトウェアです.

[ruby-list:7155] undefined class switch

From: keiju@... (Keiju ISHITSUKA)
Date: 1998-03-18 05:00:44 UTC
List: ruby-list #7155
けいじゅ@日本ラショナルソフトウェアです.

サブジェクトがわけ分からんですが(^^;;; 未定義変数(クラス)を含む可能性
のあるswitchをエレガントに書く方法を教えて下さい.

Bigfloatの件なんですが, 以下のようにタイプスイッチを行なっています.

  def /(other)
    case other
    when Bigfloat
      #break
    when Integer, Rational
      self / Bigfloat(other)
    when Float
      Float(self) / other
    when Complex
      Complex(self) / other
    else
      x, y = other.coerce(self)
      x / y
    end

    ...

ここで問題になるのが, このままだと, 本来必要のないComplexやRationalを
requireしないといけなくなります. で, requireしなくとも動作するようにし
たいのですが...

今思いつく幾つかの方法をあげますと:

1. ifを使う.

  def /(other)
    case other
    when Bigfloat
      #break
    when Integer
      self / Bigfloat(other)
    when Float
      Float(self) / other
    else
      if defined?(Complex) and Complex === other
        Complex(self) / other
      elsif defined?(Rational) and Rational === other
        self / Bigfloat(other)
      else
        x, y = other.coerce(self)
        x / y
      end
    end

と ifでその中で分岐するか... 
# 全部ifでも良いですが...

とにかくあまりエレガントではないですよね...

2. クラスをダミーで定義する.

  class Rational < Numeric; end
  class Complex < Numeric; end

  def /(other)
    case other
    when Bigfloat
      #break
    when Integer, Rational
      self / Bigfloat(other)
    when Float
      Float(self) / other
    when Complex
      Complex(self) / other
    else
      x, y = other.coerce(self)
      x / y
    end
    ...

このようにとりあえずクラスを定義しちゃうか... 

これも, ダミーでクラスを作っちゃうのが気になりますよね... さらに, スー
パクラスを指定しないで: 

  class Rational; end
  class Complex; end

こんな感じならまだ良いのですが... スーパクラスを指定しないといけないの
が, すっごく気になります.

3. 
完全ではないのですが,

  def /(other)
    case other
    when Bigfloat
      #break
    when Integer, defined?(Rational) and Rational
      self / Bigfloat(other)
    when Float
      Float(self) / other
    when defined?(Complex) and Complex
      Complex(self) / other
    else
      x, y = other.coerce(self)
      x / y
    end

というのもありますが, otherがfalseの時に変なところでマッチしてしまいま
すので... 完全にするには, 以下のようなコードが必要になります.

  def /(other)
    case other
    when false
      ....
    when Bigfloat
      #break
    when Integer, defined?(Rational) and Rational
      self / Bigfloat(other)
    when Float
      Float(self) / other
    when defined?(Complex) and Complex
      Complex(self) / other
    else
      x, y = other.coerce(self)
      x / y
    end

やはりfalseの辺りが間接的で気分が良くないですねえ...

なんかもうちょっとエレガントな方法がありませんかねえ...

__
..............................石塚 圭樹@日本ラショナルソフトウェア...
----------------------------------->> e-mail: keiju@rational.com <<---

In This Thread

Prev Next