Re: Rails 2.2.2 to_date and to_datetime methods

Julian Leviston
Thu, 05 Feb 2009 00:16:08 -0000

Basic oop. Classes have class methods, instances hve instance methods.
Makes sense if you understand what a class is. Animal is a class. If
you want to create an instance, you say Animal.new. That gives you an
animal object which is not the class. It would have been better if
they''d called it new_instance, coz that''s what it does. Now
the
instance is a particular one. It''s my cat named mrs Peabody. The class
represents the blueprint of what it is to be animal without any
particulars. I can''t tell my cat "new" coz she
doesn''t respond to that
method. Only the class does. In this way, also, classes don''t respond
to instance methods. Animal couldn''t tell you its hair colour for
instance - it doesn''t have hair. It does know that animals have hair
though! Get it? This is why active record model classes respond to the
find command. The model class represents the set of all of that class
of things, hence it''s fairly well synonymous with a table of data Whig
is a collection of the PARTICULARs of that class of things. You
couldn''t get a particular instance of a model object to find another
object for instance. - unless you particularly wanted that behaviour.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 05/02/2009, at 7:27 AM, James Byrne <rails-mailing-list@andreas-
s.net> wrote:

>
> In the console I see this behaviour:
>
>
>>> "19270412000000".to_date.methods
> => ["ns?", "mon", "ago",
"end_of_month", "months_since",
> "default_inspect", "minus_without_duration", ...
>>> "19270412000000".to_date.class
> => Date
>>> "19270412000000".class
> => String
>>> String.to_date.methods
> NoMethodError: undefined method `to_date'' for String:Class
>        from (irb):23
>
> Can someone explain how a method may be present in an object instance
> but not in the object class?  Does Rails insert singleton methods into
> these instances?
> --
> Posted via http://www.ruby-forum.com/.
>
> >