Hi --

On Sat, 27 Jun 2009, Fernando Guillen wrote:

> Hi people.. I was watching the Dave Thomas' talk on the ScotlandOnRails
> 2009 event about Ruby and the Object.
>
> He say that a class does not exists on the Ruby land, a class is just an
> instance of Class class.
>
> So I was wondering, how could I define a 'class' without using the class
> sentence .. I mean:
[...]
> So my questions are:
>
> 1) It is possible to obtain a total behavior of a Class constant without
> the 'class' sentence?

Yes; you can use a block (among other techniques, like class_eval).

   c = Class.new do
     def instance_method
       puts "hi from instance"
     end
     def self.class_method
       puts "hi from class"
     end
   end

   c.new.instance_method   # hi from instance
   c.class_method          # hi from class

> 2) What is the 'class' sentence?, because it is not a instance_method of
> 'main' that is an instance of Object, the Object#class method returns
> the name of the class of the instance but not receive any kind of
> arguments.

"class" on its own is a keyword, not a method. It's in the same family
as def, if, case, return, next... and a whole bunch of others.


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
"Ruby 1.9: What You Need To Know" Envycasts with David A. Black
http://www.envycasts.com