[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Passing an Object Class from a method to a caller

dblack

9/11/2003 9:29:00 PM

1 Answer

mgarriss

9/11/2003 11:03:00 PM

0

dblack@superlink.net wrote:

>Hi --
>
>On Fri, 12 Sep 2003, Michael Garriss wrote:
>
>
>
>>RLMuller wrote:
>>
>>
>>
>>>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 = [Array, String, Numeric, Fixnum, Struct, MatchData]
>>> result = Object
>>> i = 0
>>> for t in aTypes
>>> i += 1
>>> if o.is_a?t then
>>> result=t
>>> print "Index = #{i.to_s}: Type = ''#{t.to_s}''\n"
>>> break
>>> end
>>> result
>>> end
>>>end
>>>
>>>
>>Looks like your ''break'' is passing the ''result'' line and thus returning
>>the result of ''print''.
>>
>>
>
>I think it''s actually returning the result of break, which is nil
>(but can be assigned with "break val" in 1.8.0).
>
>
>
def this
break "cool" while true
end
--> nil
this
--> "cool"

I can''t remember the last day I went without learning something cool
about Ruby.

Michael