Project

General

Profile

Feature #12533

Updated by akhramov (Artem Khramov) about 4 years ago

Right now this isn't possible: 

 ~~~ruby <pre> 
 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' methodvegetables' for "tomatoe":String 
 ~~~ </pre> 

 Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514).  

 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.

Back