[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    [ruby-core:76181] [Ruby trunk Bug#12530] Module Refinements
From:       pavlo.vavruk () gmail ! com
Date:       2016-06-28 15:10:19
Message-ID: redmine.journal-59387.20160628151019.2360cbe9027a9f72 () ruby-lang ! org
[Download RAW message or body]

Issue #12530 has been updated by Pavlo Vavruk.

ruby -v changed from 2.3.1 to ruby 2.3.1p112

----------------------------------------
Bug #12530: Module Refinements
https://bugs.ruby-lang.org/issues/12530#change-59387

* Author: Pavlo Vavruk
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.1p112
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic