Project

General

Profile

Bug #12530

Module Refinements

Added by noxxxname (Pavlo Vavruk) about 3 years ago. Updated about 3 years ago.

Status:
Rejected
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.3.1p112
[ruby-core:76180]

Description

Hi guys, I noticed strange situation with module refinements.

There is difference with using methods which you refine.

User.new.users will return ["a", "b", "c", "d%"]
User.new.users_not_work will fail with error "undefined method `apply_user_name!' for "a":String"

 module Punctuations
    refine String do
      COMMON_PUNCTUATION = %w(. , ! ?)

      def apply_user_name!
        chop! if COMMON_PUNCTUATION.include?(last)
      end
    end
  end

  class User
    using Punctuations

    def names
      ["a", "b.", "c!", "d%"]
    end

    def users
      names.each { |word| word.apply_user_name! }
    end

    def users_not_work
      names.each(&:apply_user_name!)
    end
 end

Related issues

Is duplicate of Ruby master - Feature #12079: Loosening the condition for refinementRejectedActions

History

Updated by noxxxname (Pavlo Vavruk) about 3 years ago

  • ruby -v changed from 2.3.1 to ruby 2.3.1p112

Updated by shugo (Shugo Maeda) about 3 years ago

  • Assignee set to shugo (Shugo Maeda)
  • Status changed from Open to Rejected

This is not a bug, but an expected behavior.
However, changing this behavior is being discussed in #12079.

#3

Updated by shugo (Shugo Maeda) about 3 years ago

  • Is duplicate of Feature #12079: Loosening the condition for refinement added

Also available in: Atom PDF