Project

General

Profile

Feature #16790

Updated by sawa (Tsuyoshi Sawada) over 4 years ago

I did: 

 ```ruby 
 require 'pathname' 
 module PathRefinement 

   refine Pathname do 

     def to_s 
      '"%s"' % self  
     end 
   end 

 end 


 module Builder 

   using PathRefinement 


   def call(s,params) 
     cmd = s % params 
     puts cmd 
     system(cmd) 
   end 

   module_function :call 
 end 

 file = Pathname($0).expand_path 

 Builder.call("cat %s", file) 
 ``` 

 I got: ------------------- 

 ```sh 
 C:\Users\Dominic E Sisneros\source\repos\ruby\refine_pathname>ruby system_refinement.rb 
 cat C:/Users/Dominic E Sisneros/source/repos/ruby/refine_pathname/system_refinement.rb 
 cat: 'C:/Users/Dominic': No such file or directory 
 cat: E: No such file or directory 
 cat: Sisneros/source/repos/ruby/refine_pathname/system_refinement.rb: No such file or directory 
 ``` 

 I expected: 

 ```sh 
 expected  

 cat \"C:/Users/Dominic E Sisneros/source/repos/ruby/refine_pathname/system_refinement.rb\" 
 ``` 

 because format `%s` %s is supposed to call `to_s`. to_s 

Back