Project

General

Profile

Actions

Feature #12533

closed

Refinements: allow modules inclusion, in which the module can call internal methods which it defines.

Added by chucke (Tiago Cardoso) almost 8 years ago. Updated over 2 years ago.

Status:
Closed
Target version:
-
[ruby-core:76197]

Description

Right now this isn't possible:

module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String

Wrongly reported as a bug here.

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #14012: NameError is raised when use class variables in RefinementsRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0