From: RLMuller Date: 2003-09-12T05:33:00+09:00 Subject: Passing an Object Class from a method to a caller This is a multi-part message in MIME format. ------=_NextPart_000_004C_01C37882.24993D90 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hi All, I can't seem to pass an Object Class from a method to a calling routine Here's what I wrote: def getTypeOf(o) aTypes =3D [Array, String, Numeric, Fixnum, Struct, MatchData] result =3D Object i =3D 0 for t in aTypes i +=3D 1 if o.is_a?t then=20 result=3Dt print "Index =3D #{i.to_s}: Type =3D '#{t.to_s}'\n" break end result end end obj =3D "abc" print "Type of object '#{obj.to_s}' is '#{getTypeOf(obj).to_s}'\n\n}" =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Here's what I get when running under SciTE: ndex =3D 2: Type =3D 'String' Type of object 'abc' is '' = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D I originally tried to place the .to_s after "result" in the subroutine, = instead of after the invocation of getTypeOf, to no avail. Any ideas? TIA, Regards, Richard A programmer is a device for turning coffee into code. Jeff Prosise (with an assist from Paul Erdos) ------=_NextPart_000_004C_01C37882.24993D90 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
Hi All,
 
I can't seem to pass an Object Class from a method = to a=20 calling routine
 
Here's what I wrote:
 
def = getTypeOf(o)
       =20 aTypes =3D [Array, String, Numeric, Fixnum, Struct,=20 MatchData]
        result =3D=20 Object
        i =3D=20 0
        for t in=20 aTypes
          &nb= sp; i=20 +=3D = 1
            = if=20 o.is_a?t then=20
           &nb= sp;   =20 result=3Dt
          = ;     =20 print "Index =3D #{i.to_s}: Type =3D=20 '#{t.to_s}'\n"
         &= nbsp;     =20 break
          &nbs= p;=20 end
       =20 result
        = end
end
 
obj =3D "abc"
print "Type of object '#{obj.to_s}' = is=20 '#{getTypeOf(obj).to_s}'\n\n}"
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 
Here's what I get when running under = SciTE:
 
ndex =3D 2: Type =3D 'String'
Type of object = 'abc' is=20 ''
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 
I originally tried to place the .to_s after "result" = in the=20 subroutine, instead of after the invocation of getTypeOf, to no=20 avail.
 
Any ideas?
 
TIA,
Regards,
Richard
 
A programmer is a device for turning coffee into = code.
Jeff=20 Prosise (with an assist from Paul Erdos)
------=_NextPart_000_004C_01C37882.24993D90--