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 > confusion over 1.8.5 and 1.8.6 behavior of private
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
confusion over 1.8.5 and 1.8.6 behavior of private

Réponse
 
LinkBack Outils de la discussion
Vieux 14/09/2007, 21h53   #1
Kevin Barnes
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut confusion over 1.8.5 and 1.8.6 behavior of private

I noticed some interesting behavior when implementing some
metaprogramming techniques with private. This is dependent on why's
metaid gem/library. I have included metaid at the end in case folks
are not familiar with it.

In 1.8.5 the output is:
true
true
true

In 1.8.6 the output is:
true
true
false

require 'metaid'

module NoSeeUm
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def see(name)
meta_eval do
define_method("#{name}_public") { puts "I'm public" }
define_method("#{name}_private") { puts "I'm private" }
private ("#{name}_private").to_sym
private
define_method("#{name}_maybe_private") { puts "I may be private" }
end
end

end
end

class Reveal
include NoSeeUm
see :me
end

p Reveal.public_methods.include?('me_public')
p Reveal.private_methods.include?('me_private')
p Reveal.private_methods.include?('me_maybe_private' )

### Metaid ###

# Metaid == a few simple metaclass er
# (See http://whytheluckystiff.net/articles...esClearly.html.)
class Object
# The hidden singleton lurks behind everyone
def metaclass; class << self; self; end; end
def meta_eval &blk; metaclass.instance_eval &blk; end

# Adds methods to a metaclass
def meta_def name, &blk
meta_eval { define_method name, &blk }
end

# Defines an instance method within a class
def class_def name, &blk
class_eval { define_method name, &blk }
end
end

Just wondering why the me_maybe_private method doesn't show up in the
list of private methods in 1.8.6? Which version of Ruby is 'right'?

Thanks,
Kevin

  Réponse avec citation
Vieux 16/09/2007, 22h07   #2
Rick DeNatale
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: confusion over 1.8.5 and 1.8.6 behavior of private

On 9/14/07, Kevin Barnes <vinbarnes@gmail.com> wrote:
> I noticed some interesting behavior when implementing some
> metaprogramming techniques with private. This is dependent on why's
> metaid gem/library. I have included metaid at the end in case folks
> are not familiar with it.
>
> In 1.8.5 the output is:
> true
> true
> true
>
> In 1.8.6 the output is:
> true
> true
> false


> Just wondering why the me_maybe_private method doesn't show up in the
> list of private methods in 1.8.6? Which version of Ruby is 'right'?
>



No idea which is right. I wasn't aware of a difference between 1.8.5 and 1.8.6.

This touches on something I blogged about not too long ago:

http://talklikeaduck.denhaven2.com/a...-your-privates


--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.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 20h06.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, 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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08743 seconds with 10 queries