PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > terminology: class methods versus kernel methods
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
terminology: class methods versus kernel methods

Réponse
 
LinkBack Outils de la discussion
Vieux 23/10/2007, 23h30   #1
Thufir
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut terminology: class methods versus kernel methods

"One secret about kernel methods like print: they are
actually class methods," according to why's poignant guide to ruby.
This is frustrating for me, because I first thought "oh, that's like a
static class method, a la Math.whatever()," and then accepted the
"kernel" terminology.

Kernel means class methods?


  Réponse avec citation
Vieux 23/10/2007, 23h43   #2
Ola Bini
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

Thufir wrote:
> "One secret about kernel methods like print: they are
> actually class methods," according to why's poignant guide to ruby.
> This is frustrating for me, because I first thought "oh, that's like a
> static class method, a la Math.whatever()," and then accepted the
> "kernel" terminology.
>
> Kernel means class methods?
>
>

No. Kernel methods are methods defined on the Kernel module.

Class methods is not strictly correct either. print and others are
usually called module methods.

Cheers

--
Ola Bini (http://ola-bini.blogspot.com)
JRuby Core Developer
Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
Practical JRuby on Rails (http://apress.com/book/view/9781590598818)

"Yields falsehood when quined" yields falsehood when quined.



  Réponse avec citation
Vieux 23/10/2007, 23h45   #3
Rick DeNatale
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

On 10/23/07, Thufir <hawat.thufir@gmail.com> wrote:
> "One secret about kernel methods like print: they are
> actually class methods," according to why's poignant guide to ruby.
> This is frustrating for me, because I first thought "oh, that's like a
> static class method, a la Math.whatever()," and then accepted the
> "kernel" terminology.
>
> Kernel means class methods?


No, and I don't understand what why means.

print is an instance method of the Kernel module.

The Object class includes Kernel, so the instance methods of Kernel
are effectively instance methods of every object, at least in Ruby
1.8.

I think the only sense that print is a class method is that Module,
and therefore Class inherits it from Object which gets it from
including Kernel. In the same sense then ==, object_id, ... are class
methods. In other words classes are objects.

Ruby 1.9 introduces a BasicObject which doesn't include kernel and can
be used for advanced use cases such as proxies which need to minimize
the number of methods they implement.


--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

  Réponse avec citation
Vieux 23/10/2007, 23h57   #4
Thufir
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

On Oct 23, 2:43 pm, Ola Bini <ola.b...@gmail.com> wrote:
[...]
> > Kernel means class methods?

>
> No. Kernel methods are methods defined on the Kernel module.
>
> Class methods is not strictly correct either. print and others are
> usually called module methods.

[...]

I've got a lot to learn.


thanks,

Thufir


  Réponse avec citation
Vieux 24/10/2007, 00h00   #5
Thufir
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

On Oct 23, 2:45 pm, "Rick DeNatale" <rick.denat...@gmail.com> wrote:
[...]
> print is an instance method of the Kernel module.
>
> The Object class includes Kernel, so the instance methods of Kernel
> are effectively instance methods of every object, at least in Ruby
> 1.8.

[...]

Kernel is a class, sub-class, of Object?



-Thufir


  Réponse avec citation
Vieux 24/10/2007, 00h04   #6
Pat Maddox
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

On 10/23/07, Thufir <hawat.thufir@gmail.com> wrote:
> On Oct 23, 2:45 pm, "Rick DeNatale" <rick.denat...@gmail.com> wrote:
> [...]
> > print is an instance method of the Kernel module.
> >
> > The Object class includes Kernel, so the instance methods of Kernel
> > are effectively instance methods of every object, at least in Ruby
> > 1.8.

> [...]
>
> Kernel is a class, sub-class, of Object?
>
>
>
> -Thufir
>
>
>


No, it's a module, and it's included into Object.

baggio:~ pergesu$ irb
irb(main):001:0> Kernel.class
=> Module
irb(main):002:0> Object.included_modules
=> [Kernel]

Pat

  Réponse avec citation
Vieux 24/10/2007, 00h05   #7
David A. Black
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

Hi --

On Wed, 24 Oct 2007, Thufir wrote:

> On Oct 23, 2:45 pm, "Rick DeNatale" <rick.denat...@gmail.com> wrote:
> [...]
>> print is an instance method of the Kernel module.
>>
>> The Object class includes Kernel, so the instance methods of Kernel
>> are effectively instance methods of every object, at least in Ruby
>> 1.8.

> [...]
>
> Kernel is a class, sub-class, of Object?


Kernel is a module. Object mixes it in -- essentially:

class Object
include Kernel
end

so that every instance of Object, or a subclass of Object, gets access
to the instance methods defined in Kernel.

Of course, the module Kernel is, itself, an Object :-) You'll find
that if you look closely at the top of the object tree in Ruby, there
are some circularities:

- Kernel is a Module
- Module is a Class
- Class is a subclass of Module
- Object is a Class
- Class is an Object

etc. Don't worry about it, though. The reason there's circularity at
the top of the object tree is so that the rest of the object tree --
i.e., everything you really need to do -- makes sense.


David

--
Upcoming training by David A. Black/Ruby Power and Light, LLC:
* Advancing With Rails, Edison, NJ, November 6-9
* Advancing With Rails, Berlin, Germany, November 19-22
* Intro to Rails, London, UK, December 3-6 (by Skills Matter)
See http://www.rubypal.com for details!

  Réponse avec citation
Vieux 24/10/2007, 11h17   #8
Thufir
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

On Wed, 24 Oct 2007 07:05:52 +0900, David A. Black wrote:

> Kernel is a module. Object mixes it in -- essentially:
>
> class Object
> include Kernel
> end
>
> so that every instance of Object, or a subclass of Object, gets access
> to the instance methods defined in Kernel.


Ok. Is this composition? A work around for multiple inheritance?
Weird and wild stuff.



thanks to all,


Thufir


  Réponse avec citation
Vieux 24/10/2007, 12h01   #9
Robert Dober
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: terminology: class methods versus kernel methods

On 10/24/07, Thufir <hawat.thufir@gmail.com> wrote:
> On Wed, 24 Oct 2007 07:05:52 +0900, David A. Black wrote:
>
> > Kernel is a module. Object mixes it in -- essentially:
> >
> > class Object
> > include Kernel
> > end
> >
> > so that every instance of Object, or a subclass of Object, gets access
> > to the instance methods defined in Kernel.

>
> Ok. Is this composition? A work around for multiple inheritance?
> Weird and wild stuff.

Not at all weird and wild and neither a workaround
Mixins are one of the cornerstones of Ruby and they are not a workaround
for MI but a replacement. A deliberate and IMHO excellent choice of Matz.

Robert

--
what do I think about Ruby?
http://ruby-smalltalk.blogspot.com/

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h14.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,57580 seconds with 17 queries