Project

General

Profile

Actions

Bug #12530

closed

Module Refinements

Added by noxxxname (Pavlo Vavruk) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
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 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #12079: Loosening the condition for refinementRejectedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0