1.class vs method1.class

  • Thread starter SpringFlowers AutumnMoon
  • Start date
S

SpringFlowers AutumnMoon

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.
 
J

James Edward Gray II

so 1.class will give Fixnum...

but when i define a method

def foo
puts "ha"
end

how can i invoke

foo.class
=> Method

Hope that helps.

James Edward Gray II
 
M

Marcin Raczkowski

SpringFlowers said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,007
Latest member
Elvis60357

Latest Threads

Top