From: sawadatsuyoshi@... Date: 2020-03-23T10:57:04+00:00 Subject: [ruby-core:97579] [Ruby master Feature#16703] Namespace parameter for `Module#name` Issue #16703 has been reported by sawa (Tsuyoshi Sawada). ---------------------------------------- Feature #16703: Namespace parameter for `Module#name` https://bugs.ruby-lang.org/issues/16703 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal ---------------------------------------- I often see code that intends to remove a portion of the namespace from a module/class name like this: ```ruby class A; class B class C; end end end A::B::C.name.delete_prefix("A::") # => "B::C" A::B::C.name.delete_prefix("A::C::") # => "C" ``` I think a large portion of the use cases of the method `String#delete_prefix` are such use cases. I propose to let `Module#name` take an optional parameter that expresses the name space. The parameter should be either a module, string, or a symbol. I am not sure whether a positional argument or a keyword argument is better. Positional argument: ```ruby A::B::C.name("A") # => "B::C" A::B::C.name(:A) # => "B::C" A::B::C.name(A) # => "B::C" A::B::C.name("A::B") # => "C" A::B::C.name(:"A::B") # => "C" A::B::C.name(A::B) # => "C" ``` Keyword argument: ```ruby A::B::C.name(namespace: "A") # => "B::C" A::B::C.name(namespace: :A) # => "B::C" A::B::C.name(namespace: A) # => "B::C" A::B::C.name(namespace: "A::B") # => "C" A::B::C.name(namespace: :"A::B") # => "C" A::B::C.name(namespace: A::B) # => "C" ``` -- https://bugs.ruby-lang.org/ Unsubscribe: