# Confusion over 1.8.5 and 1.8.6 behavior of private

**URL:** <https://www.ruby-forum.com/t/confusion-over-1-8-5-and-1-8-6-behavior-of-private/114634>\
**Category:** Ruby\
**Created:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/confusion-over-1-8-5-and-1-8-6-behavior-of-private/114634 "2007-09-17T13:23:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/90ced4/32.png) [@kevben](https://www.ruby-forum.com/u/kevben)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/confusion-over-1-8-5-and-1-8-6-behavior-of-private/114634/1 "2007-09-17T13:23:24Z")

</div>

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 helper

# (See

[http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html.](http://whytheluckystiff.net/articles/seeingMetaclassesClearly.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

---

<div class="post-metadata">

**Author:** ![kevben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/90ced4/32.png) [@kevben](https://www.ruby-forum.com/u/kevben)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/confusion-over-1-8-5-and-1-8-6-behavior-of-private/114634/2 "2007-09-17T13:25:30Z")

</div>

On 9/14/07, Kevin B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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/articles/2007/09/04/block-your-privates](http://talklikeaduck.denhaven2.com/articles/2007/09/04/block-your-privates)

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
