https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-03-07T15:23:33ZRuby Issue Tracking SystemRuby master - Feature #8038: Keyword `object` to be used instead of `class <<`https://bugs.ruby-lang.org/issues/8038?journal_id=373522013-03-07T15:23:33Zdavid_macmahon (David MacMahon)davidm@astro.berkeley.edu
<ul></ul><p>As an alternative, how about allowing Object#extend to take a block that would be executed with the context such that methods defined therein would become singleton methods of the object receiving #extend?</p>
<p>Your example would then become:</p>
<p>foo = Object.new<br>
foo.extend do<br>
def bar<br>
# ...<br>
end<br>
def baz<br>
# ...<br>
end<br>
end</p>
<p>Sorry if this is impossible for some reason I don't know of,<br>
Dave</p>
<p>On Mar 6, 2013, at 9:59 PM, alexeymuranov (Alexey Muranov) wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Keyword `object` to be used instead of `class <<` (Rejected)" href="https://bugs.ruby-lang.org/issues/8038">#8038</a> has been reported by alexeymuranov (Alexey Muranov).</p>
<hr>
<p>Feature <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Keyword `object` to be used instead of `class <<` (Rejected)" href="https://bugs.ruby-lang.org/issues/8038">#8038</a>: Keyword <code>object</code> to be used instead of <code>class <<</code><br>
<a href="https://bugs.ruby-lang.org/issues/8038" class="external">https://bugs.ruby-lang.org/issues/8038</a></p>
<p>Author: alexeymuranov (Alexey Muranov)<br>
Status: Open<br>
Priority: Normal<br>
Assignee:<br>
Category: core<br>
Target version: Next Major</p>
<p>=begin<br>
I propose to introduce a new keyword (({object})) and to use it instead of the mysterious (({class <<})):</p>
<p>object foo<br>
def bar<br>
# ...<br>
end<br>
def baz<br>
# ...<br>
end<br>
end</p>
<p>instead of</p>
<p>foo = Object.new<br>
class << foo<br>
def bar<br>
# ...<br>
end<br>
def baz<br>
# ...<br>
end<br>
end<br>
=end</p>
<p>--<br>
<a href="http://bugs.ruby-lang.org/" class="external">http://bugs.ruby-lang.org/</a></p>
</blockquote> Ruby master - Feature #8038: Keyword `object` to be used instead of `class <<`https://bugs.ruby-lang.org/issues/8038?journal_id=373532013-03-07T15:26:58Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>Introducing a new keyword would break a lot of existing programs. We don't want to do unless there's strong requirement.<br>
Making Object#extend to take a block is interesting idea. We will discuss later if it's submitted.</p>
<p>Matz.</p> Ruby master - Feature #8038: Keyword `object` to be used instead of `class <<`https://bugs.ruby-lang.org/issues/8038?journal_id=373542013-03-07T17:01:53Ztrans (Thomas Sawyer)
<ul></ul><p>@alexey I sympathize. I tend to avoid <code>class << foo</code> too b/c it "reads" so poorly.</p>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/1960">@david (david he)</a> Facets extends #extend to do that actually, but it does not add the the methods directly. Instead it creates an anonymous module which it includes into the singleton class. In this way it behaves the same as extending with a module.</p> Ruby master - Feature #8038: Keyword `object` to be used instead of `class <<`https://bugs.ruby-lang.org/issues/8038?journal_id=373752013-03-08T11:52:56Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>matz (Yukihiro Matsumoto) wrote:</p>
<blockquote>
<p>Introducing a new keyword would break a lot of existing programs. We don't want to do unless there's strong requirement.<br>
Making Object#extend to take a block is interesting idea. We will discuss later if it's submitted.</p>
<p>Matz.</p>
</blockquote>
<p>I'm interested in this discussion, including Facets' interpretation. I just created <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: allow Object#extend to take a block (Open)" href="https://bugs.ruby-lang.org/issues/8046">#8046</a></p>