Issue #6335 has been updated by mame (Yusuke Endoh).

Status changed from Open to Rejected


----------------------------------------
Bug #6335: Allow Ruby hacker to extend a module or a class, without needing to know if it is a module or a class
https://bugs.ruby-lang.org/issues/6335#change-26074

Author: shevegen (markus heiler)
Status: Rejected
Priority: Low
Assignee: 
Category: 
Target version: 
ruby -v: All Ruby


Hi,

Please correct me if I am wrong.

I think in order to extend a module or a class, you must do
something like this (first, two examples, one for module,
one for a class):

  module Foo
    def test
      puts 'This is test from module Foo.'
    end
  end

  class Bar
    def test
      puts 'This is test from class Bar.'
    end
  end

Now to modify the behaviour:

  module Foo
    def test
      puts 'This is test from module Foo, but modified.'
    end
  end

  class Bar
    def test
      puts 'This is test from class Bar, but modified.'
    end
  end

My question is, why does the Ruby hacker need to know that he 
modifies a class or a module? It feels like a (small) obstacle
for no real gain I can see.

I would propose something else like:

extend Bar
  def test
    puts 'We now modified Bar but we don't care whether it is a module or a class.'
  end
end

I am not sure about "extend" as keyword. I thought about other keywords, but I could
not find good ones. So I also have to admit that sticking to "class" and "module" as
we do right now is not a bad solution - because we don't need any new word.

Still I wanted to suggest this, so that I can understand the design decision better.

Thank you for reading.


-- 
http://bugs.ruby-lang.org/