Issue #4877 has been updated by Lazaridis Ilias.


Florian Gilcher wrote:
> "#test" is used _very_ often, especially in many test suites out there, as it is the notation used for instance methods in Ruby. So changing this would break _a lot of code_, for example: https://github.com/datamapper/dm-core/blob/master/spec/unit/mash_spec.rb.

I understand, this sounds like a valid reason.

Still, there are other options to "Unify Variable Expansion within Strings" (see examples, added a new one).

 * puts "Expand #$g, #@@c and #@i - similar to #{l} and #{f}."   (current status)

 * puts "Expand #$g, #@@c and #@i - similar to ##l and ##f."     (double "#" - expansion marker & pseudo prefix)

 * puts "Expand ~$g, ~@@c and ~@i - similar to ~l and ~f."       (another char, usual way via # and #{} remains)

 * puts "Expand {$g}, {@@c} and {@i} - similar to {l} and {f}."  (omit the # char)

----------------------------------------
Feature #4877: Unify Variable Expansion within Strings
http://redmine.ruby-lang.org/issues/4877

Author: Lazaridis Ilias
Status: Rejected
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: core
Target version: 


class VarTester
  $g = "global" 
  @@c = "class"
  
  def f
    "function"
  end

  def initialize
    @i = "instance"
    l = "local"
    puts "#$g #@@c #@i #l #f #{l} #{f}"
  end
end

VarTester.new 

#=> global class instance #l #f local function

=== User Context ===

3 variable types (Class- instance- and global) can be expanded by prefixing a single char ("#") (without the need to add "{}").

This should be enabled for local vars and ideally for functions, too (at least the attr accessors).

=== Pro ===

* consistent expansion of all variable types via "#"
* reduced typing (use of {} is optional)
* increased readability of strings which contain many variables.

=== Contra ===

?

=== Compatibility ===

This would break slightly existent behaviour:

 existent '#text' within strings would be expanded (should be a rare case)






-- 
http://redmine.ruby-lang.org