[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Overriding new?
From:       Ken Bloom <kbloom () gmail ! com>
Date:       2010-03-15 19:08:19
Message-ID: pan.2010.03.15.19.01.19 () gmail ! com
[Download RAW message or body]

On Tue, 16 Mar 2010 00:04:59 +0900, Andrea Dallera wrote:

> Hi everybody,
> 
> 	the whole issues comes from here:
> http://github.com/bolthar/freightrain/blob/master/lib/freightrain/
freight_view_model.rb
> FreightViewModel is part of the framework, and if you're using it that's
> the way you should do it:
> 
> class MyViewModel < FreightViewModel
> 
> ...
> 
> end
> 
> what i don't like is that if you want to make _your_ viewmodel do stuff
> on initialize, which is usual, you have to write your initialize method
> as such:
> 
> def initialize
>   super
>   #your stuff here
> end
> 
> otherwise the automagical initialization (like building views, hooking
> to services, etc) doesn't work, because the constructor of
> FreightViewModel (that is the one taking care of all this) doesn't get
> called.
> I know this is not extremely important (you just have to remind to call
> super) but i'd prefer not to have that hassle : i forget it myself more
> than often.

You ought to just get in the habit of remembering it.

Maybe you can write some kind of automatic checker that will look for 
definitions of initialize that don't call super.

I think it's always appropriate to call super in an initialize call, 
because everything descends from Object, and Object defines an initialize 
method.

--Ken

-- 
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic