Regard to "[ruby-list:12013] Re: to_i,to_s の素朴な疑問" 有馬@FITECです。 | まつもと ゆきひろです | |delphiだと幾つかのclassにAsStringとかAsIntegerってpropertyがあります。 | |propertyだとmethodと違ってreadもwriteも出来るんで、ToじゃなくてAsに | |なったんだと思います… | | ふむ, | | object.AsString := 25 | | とかするとナニが起きるんでしょうね.自分で調べれば良いんです | けど. それだと、コンパイルエラーになります。 Delphi だと、まず、クラスの定義が以下のようになります。 type TFoo = class private FValue: integer; protected // 内部メソッド function GetAsString: string; procedure SetAsString(Value: string); function GetAsInteger: integer; procedure SetAsInteger(Value: integer); public // 公開するプロパティ property AsString: string read GetAsString write SetAsString; property AsInteger: integer read GetAsInteger write SetAsInteger; end; TFoo 型の インスタンス foo を使うときは、以下のようになります。 var foo: TFoo; st: string; begin foo := TFoo.Create; foo.AsInteger := 0; st := foo.AsString; 結局は、右辺と左辺で別のメソッドを呼び出すことになります。 型の不整合を解消するような自動変換は、Variant 型というものを 用いたときだけ行われます。 -- 有馬 康弘 <fit0298 / fitec.co.jp>