# Code Review: Protected3

**URL:** <https://www.ruby-forum.com/t/code-review-protected3/168529>\
**Category:** IronRuby\
**Created:** [May 22, 2009, 12:33am UTC](https://www.ruby-forum.com/t/code-review-protected3/168529 "2009-05-22T00:33:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 22, 2009, 12:33am UTC](https://www.ruby-forum.com/t/code-review-protected3/168529/1 "2009-05-22T00:33:13Z")

</div>

tfpt review “/shelveset:Protected3;REDMOND\tomat”

Small changes in DLR.

Ruby:  
Fixes handling of CLR protected and private methods and properties.  
Enables generic methods in ClsTypeEmitter.  
Removes RubyCallFlag.TryCall - it’s not used anymore.

Notes on visibility:  
Ruby visibility is orthogonal to CLR visibility.  
Ruby visibility is mutable (can be changed using  
Kernel#public/private/protected methods), CLR visibility is not.  
A CLR method group can comprise of methods of different CLR  
visibility. Ruby visibility applies on the group as a whole.

Ruby-protected members can only be called from a scope whose self  
immediate class is a descendant of the method owner.  
CLR-protected members can only be called if the receiver is a  
descendant of the method owner.

Ruby-private members can only be called with an implicit receiver  
(self).  
CLR-private members can only be called in PrivateBinding mode  
(-X:PrivateBinding command line option), the receiver might be explicit  
or implicit.

Tests:  
Since protected methods can only be called on a derived class instance  
the specs need to be adjusted accordingly.  
I’ve fixed generic\_spec nad overload\_spec and commented out a block in  
protected\_spec - all the cases there need to be changed to negative  
cases (all should fail).  
Removed ROWAN\_BIN check in  
External.LCA\_RESTRICTED\Languages\IronRuby\mspec\default.mspec so that  
mspec picks up IR\_OPTIONS even if ROWAN\_BIN is not set.

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 22, 2009, 12:39am UTC](https://www.ruby-forum.com/t/code-review-protected3/168529/2 "2009-05-22T00:39:39Z")

</div>

Looks good!

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 22, 2009, 12:44am UTC](https://www.ruby-forum.com/t/code-review-protected3/168529/3 "2009-05-22T00:44:21Z")

</div>

For the protected tests, can you add specs that test that the protected  
.NET methods are callable from an instance\_eval?

@klass.instance\_eval {public\_protected\_overload(“abc”)}.should  
equal\_clr\_string(“protected overload”)

Don’t worry about protected\_spec though, I’ll fix that.

Other than that, test looks good.

JD

…there is no try

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 22, 2009, 12:56am UTC](https://www.ruby-forum.com/t/code-review-protected3/168529/4 "2009-05-22T00:56:02Z")

</div>

After chatting with Tomas, not adding those tests makes sense due to  
differences in CLR protected behavior. I misunderstood his explanation  
below.

JD

…there is no try
