Forum: Ruby-core [ruby-trunk - Feature #8839][Open] Class and module should return the class or module that was opene

F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-08-30 19:57
(Received via mailing list)
Issue #8839 has been reported by headius (Charles Nutter).

----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
0e610136db92027148906c92d57fdb36?d=identicon&s=25 marcandre (Marc-Andre Lafortune) (Guest)
on 2013-08-30 20:35
(Received via mailing list)
Issue #8839 has been updated by marcandre (Marc-Andre Lafortune).


When thinking of potential incompatibilities, the only case I could
think of where I'd ever used the result of `class` or `module` was:

    class << foo
      self
    end

Ironically, the proposed change would not introduce an incompatibility
in this case :-)
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-41439

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
Df9d48b6e2ae6cdedf4c39c2e58df851?d=identicon&s=25 boris_stitnicky (Boris Stitnicky) (Guest)
on 2013-08-31 11:26
(Received via mailing list)
Issue #8839 has been updated by boris_stitnicky (Boris Stitnicky).


+1
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-41487

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-25 23:42
(Received via mailing list)
Issue #8839 has been updated by headius (Charles Nutter).


So...if there's no objections, can we get this into 2.1? I think with
the new def return value change it really needs to happen.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-41977

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 enebo (Thomas Enebo) (Guest)
on 2013-09-25 23:43
(Received via mailing list)
Issue #8839 has been updated by enebo (Thomas Enebo).


+1
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-41978

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-09-26 04:57
(Received via mailing list)
Issue #8839 has been updated by nobu (Nobuyoshi Nakada).


No, class and def are evaluated in different timings.
This proposal makes no sense.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-41983

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F736999f7c1b7a87a100faa112bbc0f3?d=identicon&s=25 charliesome (Charlie Somerville) (Guest)
on 2013-09-26 05:03
(Received via mailing list)
Issue #8839 has been updated by charliesome (Charlie Somerville).


nobu: I don't understand what you mean by "evaluated in different
timings". Could you please explain?

I think this proposal is a good idea. For example, this makes no sense:

    class A
      def foo
      end
    end # => :foo

But this makes more sense:

    class A
      def foo
      end
    end # => A
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-41984

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2013-09-26 13:22
(Received via mailing list)
Issue #8839 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)
Target version set to next minor

How useful is this proposal?
I think we should not change anything without consideration of use case.

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-41996

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
2abdb50caf0dc5b510330f68b02db8e4?d=identicon&s=25 rosenfeld (Rodrigo Rosenfeld Rosas) (Guest)
on 2013-09-26 21:22
(Received via mailing list)
Issue #8839 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


I've been wondering the same thing since I saw this ticket being
created...
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42019

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
2abdb50caf0dc5b510330f68b02db8e4?d=identicon&s=25 rosenfeld (Rodrigo Rosenfeld Rosas) (Guest)
on 2013-09-26 21:23
(Received via mailing list)
Issue #8839 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


Actually, I don't understand even why returning a symbol from method
definition is useful...
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42020

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-27 12:29
(Received via mailing list)
Issue #8839 has been updated by headius (Charles Nutter).


mame (Yusuke Endoh) wrote:
> How useful is this proposal?
> I think we should not change anything without consideration of use case.

One use:

my_class = class Foo
  ...
end

We can get the reference to a class being created immediately without
adding "self" at the end. It also brings some equivalence with my_class
= Class.new.

Another:

class Foo
  def self.init
    @foo = Foo.new
  end
end.init

The use cases I can think of are all fairly subtle, but I think they're
valid.

Ultimately, the biggest reason I think this should happen is because
class Foo; def bar; end; end returning :bar in 2.1 makes very little
sense.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42029

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
2abdb50caf0dc5b510330f68b02db8e4?d=identicon&s=25 rosenfeld (Rodrigo Rosenfeld Rosas) (Guest)
on 2013-09-27 14:11
(Received via mailing list)
Issue #8839 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


I see now. I really tried a few times to get something like your second
example to work:

class MyProcessor
 ...
end.new(params).process

I'd usually use such pattern in small scripts since methods are not
hoisting like functions declarations in JavaScript and I prefer to write
code top-down, so I enclose them in a class.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42048

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2013-09-27 16:33
(Received via mailing list)
Issue #8839 has been updated by mame (Yusuke Endoh).


headius (Charles Nutter) wrote:
> One use:
>
> my_class = class Foo
>   ...
> end
>
> We can get the reference to a class being created immediately without adding
"self" at the end.

I fail to see why it needs to be a local variable.
Why don't you use Foo instead of my_class?


> Another:
>
> class Foo
>   def self.init
>     @foo = Foo.new
>   end
> end.init
>
> The use cases I can think of are all fairly subtle, but I think they're valid.

It is very arguable if the new idiom should be encouraged.
Personally, I don't like to see such a code.  Rather, I prefer:

  class Foo
    def self.init
      @foo = Foo.new
    end
    self.init
  end

or even:

  class Foo
    @@foo = Foo.new
  end


> Ultimately, the biggest reason I think this should happen is because class Foo;
def bar; end; end returning :bar in 2.1 makes very little sense.

IMHO, most of casual users do not care too much for a return value.
For example, we often see the following type of code:

  def foo
    internal_ary = []
    # ... building internal_ary ...
    internal_ary.each do |elem|
      # ... using elem ...
    end
  end

Obviously, the author of this method has no intent to return
internal_ary.
But, few people writes a code that returns nil explicitly to hide the
value.

  def foo
    internal_ary = []
    # ...
    internal_ary.each do |elem|
      # ...
    end
    nil
  end

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42051

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-27 20:40
(Received via mailing list)
Issue #8839 has been updated by headius (Charles Nutter).


mame (Yusuke Endoh) wrote:
> Why don't you use Foo instead of my_class?
How about this:

meta = class << self; end

> or even:
>
>   class Foo
>     @@foo = Foo.new
>   end

I respect your opinion, but I fail to see why your way is better than
mine.

> > Ultimately, the biggest reason I think this should happen is because class
Foo; def bar; end; end returning :bar in 2.1 makes very little sense.
>
> IMHO, most of casual users do not care too much for a return value.

Users not caring about return value is not a good reason to return a
nonsensical value. Returning the last method name defined in a class
body makes no sense. Returning the class that was just defined may not
make sense to you, but it makes sense to me and several others who have
commented here.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42055

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 robertgleeson (Robert Gleeson) (Guest)
on 2013-09-27 21:21
(Received via mailing list)
Issue #8839 has been updated by robertgleeson (Robert Gleeson).


I agree that returning the class or module makes sense (to me).
I'd also like to see "def foo" return a (Unbound)Method instead of a
Symbol.
it seems like that'd also make more sense (not to derail this
conversation). A (Unbound)Method is much more useful.
I saw headius mention you can say:
i
nstance_method def foo
end # => UnboundMethod.

...but seems like a nice default.

+1 to the proposal.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42058

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2013-09-28 01:41
(Received via mailing list)
Issue #8839 has been updated by mame (Yusuke Endoh).


headius (Charles Nutter) wrote:
> > I fail to see why it needs to be a local variable.
> > Why don't you use Foo instead of my_class?
>
> How about this:
>
> meta = class << self; end

Use:

  meta = self.singleton_class


> > or even:
> >
> >   class Foo
> >     @@foo = Foo.new
> >   end
>
> I respect your opinion, but I fail to see why your way is better than mine.

Your way is too easy to overlook ".init" because a method call is not
usually expected there.


> > > Ultimately, the biggest reason I think this should happen is because class
Foo; def bar; end; end returning :bar in 2.1 makes very little sense.
> >
> > IMHO, most of casual users do not care too much for a return value.
>
> Users not caring about return value is not a good reason to return a nonsensical
value.

"It makes no sense" is not a good reason to change anything.
Rather, it is consistent and compatible to just return the last value.
We need better reason to break compatibility, I think.

This is my personal opinion, of course.

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42060

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 shugo (Shugo Maeda) (Guest)
on 2013-09-28 08:40
(Received via mailing list)
Issue #8839 has been updated by shugo (Shugo Maeda).


I did a quick hack to try this proposal and found that some test failed
with it:

  https://gist.github.com/shugo/6739085

For example, bootstraptest/test_block.rb uses the last value of a class
definition as follows:

assert_equal 'ok', %q{
  STDERR.reopen(STDOUT)
  class C
    define_method(:foo) do |&block|
      block.call if block
    end
    result = "ng"
    new.foo() {result = "ok"}
    result
  end
}

If class definitions are changed to return the defined class, there'll
be no way to get values created in class definitions except using global
variables or constants, etc.
I'm not sure whether there's any use case of the current behavior other
than testing purposes, but please consider there might be some users of
the current behavior.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42068

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-09-30 15:20
(Received via mailing list)
Issue #8839 has been updated by headius (Charles Nutter).


shugo (Shugo Maeda) wrote:
> I did a quick hack to try this proposal and found that some test failed with it:
>
>   https://gist.github.com/shugo/6739085
>
> For example, bootstraptest/test_block.rb uses the last value of a class
definition as follows:

The case given is rather contrived; I have never seen code in the wild
use last expression return from a class.

> If class definitions are changed to return the defined class, there'll be no way
to get values created in class definitions except using global variables or
constants, etc.

This is a fair point, I suppose, but I still see more reasons to make
the return value consistent than leave it as is and have classes
suddenly returning a symbol for the last defined method. Most folks
probably don't even know about the return value since if you're just
doing "def" as last expression it has always been nil.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42103

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
4dea430d31b993abaf41cd9b54f8128d?d=identicon&s=25 Avdi Grimm (avdi)
on 2013-09-30 16:41
(Received via mailing list)
On Sat, Sep 28, 2013 at 2:39 AM, shugo (Shugo Maeda)
<redmine@ruby-lang.org>wrote:

> For example, bootstraptest/test_block.rb uses the last value of a class
> definition as follows:


The only time I've ever used the return value of a class definition it's
been to get the class itself, by making `self` the last statement in the
class definition.

That said, if you really wanted to preserve the ability to return
something
other from a class definition, could you make `break <SOME_VALUE>`
override
the return, as it does in blocks?

--
Avdi Grimm
http://avdi.org

I only check email twice a day. to reach me sooner, go to
http://awayfind.com/avdi
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-01 02:38
(Received via mailing list)
Issue #8839 has been updated by headius (Charles Nutter).


avdi (Avdi Grimm) wrote:
>  That said, if you really wanted to preserve the ability to return something
>  other from a class definition, could you make `break <SOME_VALUE>` override
>  the return, as it does in blocks?

That wouldn't be backward-compatible with anyone expecting last
expression, but it's an excellent idea to address Shugo's concern.
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42119

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
E8a419959139f3f505b49bb95f7e7afe?d=identicon&s=25 Joshua Ballanco (jballanc)
on 2013-11-07 09:35
(Received via mailing list)
Issue #8839 has been updated by jballanc (Joshua Ballanco).


=begin
Just to throw my 2ยข in...

I think the main benefit to returning a symbol from (({def})) is that it
enables the use of method decorators. Similarly, I would be in favor of
returning the class defined from (({class})) so that we could also build
class decorators. A trivial example:

    def enumerable(klass)
      klass.send(:include, Enumerable)
      klass
    end

    enumerable
    class Foo
      #...
    end

=end

----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42795

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-11-07 20:04
(Received via mailing list)
Issue #8839 has been updated by headius (Charles Nutter).


jballanc (Joshua Ballanco) wrote:
>     enumerable
>     class Foo
>       #...
>     end
>
> =end

=begin
Clever! Though I don't think that would parse the way you want. This
would work though, obviously:

  enumerable class Foo ...

=end
----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-42807

Author: headius (Charles Nutter)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: next minor


With the change for https://bugs.ruby-lang.org/issues/3753, "def" forms
now return the symbolic name of the method defined. Because class and
module bodies just return the last expression in their bodies, this
means they will now usually end up returning a symbol for the last
method defined. This does not seem useful or correct.

I think class and module should return a reference to the class or
module just opened. This would make the return value useful and
consistent.
63c72161fba6e27cb05c078651c5e969?d=identicon&s=25 Alexey Muranov (alexey_m)
on 2014-06-16 23:05
(Received via mailing list)
Issue #8839 has been updated by Alexey Muranov.


+1.  I do not want to share my silly code where i would use it, but
currently it may look something like that:

```ruby
def MyClass
  # ...
  self
end.define_more_methods(x, y, z).freeze
```

----------------------------------------
Feature #8839: Class and module should return the class or module that
was opened
https://bugs.ruby-lang.org/issues/8839#change-47250

* Author: Charles Nutter
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category:
* Target version: next minor
This topic is locked and can not be replied to.