[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

1.class vs method1.class

SpringFlowers AutumnMoon

9/19/2007 1:20:00 PM

so 1.class will give Fixnum...

but when i define a method

def foo
puts "ha"
end

how can i invoke

foo.class

as it is taking what foo returns... as then invoke class on that.
--
Posted via http://www.ruby-....

2 Answers

James Gray

9/19/2007 1:27:00 PM

0

On Sep 19, 2007, at 8:19 AM, SpringFlowers AutumnMoon wrote:

> so 1.class will give Fixnum...
>
> but when i define a method
>
> def foo
> puts "ha"
> end
>
> how can i invoke
>
> foo.class

>> def foo; end
=> nil
>> method(:foo).class
=> Method

Hope that helps.

James Edward Gray II

Marcin Raczkowski

9/19/2007 1:29:00 PM

0

SpringFlowers AutumnMoon wrote:
> so 1.class will give Fixnum...
>
> but when i define a method
>
> def foo
> puts "ha"
> end
>
> how can i invoke
>
> foo.class
>
> as it is taking what foo returns... as then invoke class on that.

becouse foo returns what puts returns and it's nil, and nil have NilClass

you have to understand that in ruby EVERYTHING returns value (even if
it's nil) and everything is object (even nil)