https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-08-05T01:32:56ZRuby Issue Tracking SystemRuby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=599592016-08-05T01:32:56Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>I think it should be possible to implement locksee in pure-ruby. To me it seems OK to have a way to access visibility of a method.</p>
<p>It is not clear if locksee cannot be implemented without exposing IClass, though.</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=599682016-08-06T00:26:06Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/59968/diff?detail_id=42108">diff</a>)</li><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Mathieu Jobin wrote:</p>
<blockquote>
<p>it uses the following macros to find the method visibility and if it has been redefined</p>
<pre><code class="C syntaxhl" data-language="C"><span class="n">UNDEFINED_METHOD_ENTRY_P</span><span class="p">(</span><span class="n">me</span><span class="p">)</span>
<span class="n">METHOD_ENTRY_VISI</span><span class="p">(</span><span class="n">me</span><span class="p">)</span>
</code></pre>
</blockquote>
<p>I'd love to add the functions, but are they really needed?</p>
<blockquote>
<p>Ideally, a ruby method that would return its visibility, should return one of the following value</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">[</span><span class="ss">:public</span><span class="p">,</span> <span class="ss">:protected</span><span class="p">,</span> <span class="ss">:private</span><span class="p">,</span> <span class="ss">:undefined</span><span class="p">,</span> <span class="ss">:overridden</span><span class="p">]</span>
</code></pre>
</blockquote>
<p>I think <code>:overridden</code> doesn't make sense in ruby.<br>
What do you expect by it?</p>
<blockquote>
<p>we are using other ruby macros to find where the method is define, which module or class.</p>
<pre><code class="C syntaxhl" data-language="C"><span class="n">RCLASS_SUPER</span><span class="p">(</span><span class="n">internal_class</span><span class="p">)</span>
<span class="n">CLASS_OF</span><span class="p">(</span><span class="n">object</span><span class="p">)</span>
<span class="n">SPECIAL_CONST_P</span><span class="p">(</span><span class="n">object</span><span class="p">)</span>
<span class="n">BUILTIN_TYPE</span><span class="p">(</span><span class="n">object</span><span class="p">)</span>
<span class="n">FL_TEST</span><span class="p">(</span><span class="n">singleton_class</span><span class="p">,</span> <span class="n">FL_SINGLETON</span><span class="p">)</span>
</code></pre>
</blockquote>
<p>These would be safe.</p>
<blockquote>
<pre><code class="C syntaxhl" data-language="C"><span class="n">RCLASS_M_TBL</span><span class="p">(</span><span class="n">klass</span><span class="p">)</span>
<span class="n">RCLASS_IV_TBL</span><span class="p">(</span><span class="n">singleton_class</span><span class="p">)</span>
</code></pre>
</blockquote>
<p>It's not recommended to directly access internal members, <code>m_tbl</code>, <code>iv_tbl</code>, etc.</p>
<blockquote>
<pre><code class="C syntaxhl" data-language="C"><span class="n">RBASIC</span><span class="p">(</span><span class="n">module_or_included_class</span><span class="p">)</span><span class="o">-></span><span class="n">klass</span>
</code></pre>
</blockquote>
<p>It is preferable to use <code>RBASIC_CLASS()</code> instead of <code>RBASIC()->klass</code>.</p>
<blockquote>
<p>that is mostly it</p>
<p>you can see what I have tried for ruby 2.3<br>
<a href="https://github.com/oggy/looksee/pull/36/files#diff-d5ef4b0cfbd5a6712f37dfa7ffbe2130" class="external">https://github.com/oggy/looksee/pull/36/files#diff-d5ef4b0cfbd5a6712f37dfa7ffbe2130</a></p>
<p>I'm unable to use <code>rb_id_table_foreach</code> which seems like I would need to import too much of ruby code inside the extension... which I would prefer not including more C into this gem</p>
</blockquote>
<p>The reason to use <code>id_table</code> seems to collect methods for each visibilities.<br>
What differs from <code>rb_class_public_instance_methods</code> etc?</p>
<p>What you need are <code>rb_class_undefined_instance_methods</code> and<br>
<code>rb_class_singleton_object</code> (provisional names)?</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=599752016-08-07T17:18:38Zoggy (George Ogata)george.ogata@gmail.com
<ul></ul><p>Hi,</p>
<p>I'm the original author of looksee.</p>
<p>I agree that we don't need everything in the Looksee extension in ruby. Looksee was written back in 2009 when I think the situation was a little different, but now I believe Module#ancestors should suffice to get the chain of modules.</p>
<p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>What you need are <code>rb_class_undefined_instance_methods</code> and<br>
<code>rb_class_singleton_object</code> (provisonal names)?</p>
</blockquote>
<p>I think this is exactly right. Would you consider exposing these at the ruby level?</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=600402016-08-10T04:45:05Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>We briefly looked at this issue at yesterday's developer meeting and roughly agreed that locksee should be able to be done in pure-ruby.</p>
<p>Sad news is we had no time to have a deeper look at it so what is actually needed was not made clear at the meeting.</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=600582016-08-11T06:19:29Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p><a href="https://github.com/ruby/ruby/compare/trunk...nobu:feature/12655" class="external">https://github.com/ruby/ruby/compare/trunk...nobu:feature/12655</a></p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=603852016-09-06T23:23:24Zoggy (George Ogata)george.ogata@gmail.com
<ul></ul><p>Thanks Shyouhei! I believe I need the 2 methods Nobu has implemented in this patch here to implement Looksee entirely in ruby, which I would love to do. In the latest version of looksee I have reduced the MRI extension down to just these 2 methods, so if this were in trunk I could swap those in & try it.</p>
<p>(Or if you are reluctant to expose these at the ruby level, is there any chance they could be made available to extensions?)</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=773432019-03-27T20:31:40Zmathieujobin (Mathieu Jobin)
<ul></ul><p>I know its been two years already.<br>
but do you think we could get those new methods merged into trunk?</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=833552019-12-23T14:29:25Zmathieujobin (Mathieu Jobin)
<ul></ul><p>mri/2.x.0/internal.h:1363:11: error: conflicting types for ‘rb_st_copy’<br>
1363 | st_table *rb_st_copy(VALUE obj, struct st_table *orig_tbl);</p>
<p>looks like this has changed in ruby 2.7</p>
<p>we would have appreciated the public methods from nobu to be merged in...</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=833722019-12-24T02:50:21Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Sorry, I've forgotten completely.<br>
Updated the <a href="https://github.com/ruby/ruby/pull/2778" class="external">patch</a>, but it is sorry to be too late for 2.7.</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=833742019-12-24T04:42:42Zsawa (Tsuyoshi Sawada)
<ul><li><strong>Subject</strong> changed from <i>accessing a method visibility</i> to <i>Accessing the method visibility</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/83374/diff?detail_id=55913">diff</a>)</li></ul> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=943642021-10-27T18:50:14Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/12084">Feature #12084</a>: `Class#instance`</i> added</li></ul> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=969022022-03-17T14:00:25Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>OK, I accept introducing <code>undefined_instance_methods</code>. It returns a list of undefined methods of the receiver class.<br>
Unlike <code>instance_methods</code> etc. it should not traverse the inheritance chain.</p>
<p>Matz.</p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=970752022-03-29T21:09:05Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>I modified @nobu's patch for undefined methods to remove <code>Object#undefined_methods</code> and remove the optional argument from <code>Module#undefined_instance_methods</code>, and submitted a pull request for that: <a href="https://github.com/ruby/ruby/pull/5733" class="external">https://github.com/ruby/ruby/pull/5733</a></p> Ruby master - Feature #12655: Accessing the method visibilityhttps://bugs.ruby-lang.org/issues/12655?journal_id=978562022-06-07T05:51:57Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Add Module#undefined_instance_methods Implements [Feature #12655] Co-authored-by: Nobuyoshi Nak..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/7cda7fbbdc14f4262afaa94cdeb5a5987f1eb01a">git|7cda7fbbdc14f4262afaa94cdeb5a5987f1eb01a</a>.</p>
<hr>
<p>Add Module#undefined_instance_methods</p>
<p>Implements [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Accessing the method visibility (Closed)" href="https://bugs.ruby-lang.org/issues/12655">#12655</a>]</p>
<p>Co-authored-by: Nobuyoshi Nakada <a href="mailto:nobu@ruby-lang.org" class="email">nobu@ruby-lang.org</a></p>