List Info

Thread: Ruby on Rails... why the Base class




Ruby on Rails... why the Base class
country flaguser name
Canada
2007-07-15 13:02:50
Hello everyone,

it's been quiet around here for a while so I thought I'd
launch some 
discussion around how Rails is implementing the
ActiveRecord.

When you read the code of the active record you notice that
it follows 
that pattern

1. a class named Base that includes plenty of other modules
2. the modules are made of 2 groups... 1st a module that
contains the 
class methods... and a second that contains the object
methods...

what is the gain of proceeding like that?

Cheers! (said the guy writing to the ruby montreal newsgroup
while 
having his legs in the pool).

Jean-Marc

_______________________________________________
Rubymtl mailing list
Rubymtllists.artengine.ca
http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl

Re: Ruby on Rails... why the Base class
country flaguser name
United States
2007-07-15 15:24:19
The only gain I know of is organization of code for RDoc and
 
legibility of the code to some extent. I think the latter
reason is  
offset by the overcomplicated implementation of doing all
the mixin  
stuff though, so I'm not sure how legible ActiveRecord
actually is.  
However, it is a clean way to split a large class (large in
terms of  
LOC) into multiple files without having to re-open the class
 
arbitrarily. That said, there are other ways to organize
large bodies  
of code, and I don't quite buy into the whole Class/Instance
module  
thing myself.

Loren

On 15-Jul-07, at 11:02 AM, Jean-Marc Lagacé wrote:

> Hello everyone,
>
> it's been quiet around here for a while so I thought
I'd launch some
> discussion around how Rails is implementing the
ActiveRecord.
>
> When you read the code of the active record you notice
that it follows
> that pattern
>
> 1. a class named Base that includes plenty of other
modules
> 2. the modules are made of 2 groups... 1st a module
that contains the
> class methods... and a second that contains the object
methods...
>
> what is the gain of proceeding like that?
>
> Cheers! (said the guy writing to the ruby montreal
newsgroup while
> having his legs in the pool).
>
> Jean-Marc
>
> _______________________________________________
> Rubymtl mailing list
> Rubymtllists.artengine.ca
> http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl

_______________________________________________
Rubymtl mailing list
Rubymtllists.artengine.ca
http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl

Re: Ruby on Rails... why the Base class
country flaguser name
Canada
2007-07-15 16:05:05
Hum... Loren what other way you know?

Organizing large file can be challenging... it would be
interesting to 
see if we can come up with a pattern to determine what
approach works 
best depending on the scenario.

Jean-Marc

Loren Segal wrote:
> The only gain I know of is organization of code for
RDoc and  
> legibility of the code to some extent. I think the
latter reason is  
> offset by the overcomplicated implementation of doing
all the mixin  
> stuff though, so I'm not sure how legible ActiveRecord
actually is.  
> However, it is a clean way to split a large class
(large in terms of  
> LOC) into multiple files without having to re-open the
class  
> arbitrarily. That said, there are other ways to
organize large bodies  
> of code, and I don't quite buy into the whole
Class/Instance module  
> thing myself.
> 
> Loren
> 
> On 15-Jul-07, at 11:02 AM, Jean-Marc Lagacé wrote:
> 
>> Hello everyone,
>>
>> it's been quiet around here for a while so I
thought I'd launch some
>> discussion around how Rails is implementing the
ActiveRecord.
>>
>> When you read the code of the active record you
notice that it follows
>> that pattern
>>
>> 1. a class named Base that includes plenty of other
modules
>> 2. the modules are made of 2 groups... 1st a module
that contains the
>> class methods... and a second that contains the
object methods...
>>
>> what is the gain of proceeding like that?
>>
>> Cheers! (said the guy writing to the ruby montreal
newsgroup while
>> having his legs in the pool).
>>
>> Jean-Marc
>>
>> _______________________________________________
>> Rubymtl mailing list
>> Rubymtllists.artengine.ca
>> http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl

_______________________________________________
Rubymtl mailing list
Rubymtllists.artengine.ca
http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl

Re: Ruby on Rails... why the Base class
country flaguser name
United States
2007-07-15 20:05:30
Something I just came up with on the spot (never used this
before):

(Pastied at http://pastie.caboo.se/7
9068 for better viewing)

## loader.rb

module Loader
   def require_class(klass)
     %w(instance class).each do |w|
       require File.join(klass,w) if File.exist?
File.join(klass,w 
+'.rb')
     end
   end
end
include Loader

## my_class/instance.rb

class MyClass
   def inst_method
     puts "I'm in the instance"
   end
end

## my_class/class.rb

class << MyClass
   def class_method
     puts "I'm in the class"
   end
end

## example code:

require_class 'my_class'

MyClass.class_method      #=> "I'm in the
class"
MyClass.new.inst_method   #=> "I'm in the
instance"


On 15-Jul-07, at 2:05 PM, Jean-Marc Lagacé wrote:

> Hum... Loren what other way you know?
>
> Organizing large file can be challenging... it would be
interesting to
> see if we can come up with a pattern to determine what
approach works
> best depending on the scenario.
>
> Jean-Marc
>
> Loren Segal wrote:
>> The only gain I know of is organization of code for
RDoc and
>> legibility of the code to some extent. I think the
latter reason is
>> offset by the overcomplicated implementation of
doing all the mixin
>> stuff though, so I'm not sure how legible
ActiveRecord actually is.
>> However, it is a clean way to split a large class
(large in terms of
>> LOC) into multiple files without having to re-open
the class
>> arbitrarily. That said, there are other ways to
organize large bodies
>> of code, and I don't quite buy into the whole
Class/Instance module
>> thing myself.
>>
>> Loren
>>
>> On 15-Jul-07, at 11:02 AM, Jean-Marc Lagacé wrote:
>>
>>> Hello everyone,
>>>
>>> it's been quiet around here for a while so I
thought I'd launch some
>>> discussion around how Rails is implementing the
ActiveRecord.
>>>
>>> When you read the code of the active record you
notice that it  
>>> follows
>>> that pattern
>>>
>>> 1. a class named Base that includes plenty of
other modules
>>> 2. the modules are made of 2 groups... 1st a
module that contains  
>>> the
>>> class methods... and a second that contains the
object methods...
>>>
>>> what is the gain of proceeding like that?
>>>
>>> Cheers! (said the guy writing to the ruby
montreal newsgroup while
>>> having his legs in the pool).
>>>
>>> Jean-Marc
>>>
>>>
_______________________________________________
>>> Rubymtl mailing list
>>> Rubymtllists.artengine.ca
>>> http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl
>
> _______________________________________________
> Rubymtl mailing list
> Rubymtllists.artengine.ca
> http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl

_______________________________________________
Rubymtl mailing list
Rubymtllists.artengine.ca
http://lists.artengine.ca/cgi-bin/mailman/listinfo/rub
ymtl

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )