Project

General

Profile

Actions

Bug #6335

closed

Allow Ruby hacker to extend a module or a class, without needing to know if it is a module or a class

Added by shevegen (Robert A. Heiler) almost 12 years ago. Updated almost 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
All Ruby
Backport:
[ruby-core:44514]

Description

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.


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Feature #6336: Allow Ruby hacker to extend a module or a class, without needing to know if it is a module or a classRejected04/22/2012Actions

Updated by mame (Yusuke Endoh) almost 12 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0