Issue #7849 has been updated by trans (Thomas Sawyer).


=begin
@charliesome Actually, that's exactly what my proposal attempts to address. You don't always have a choice in what type of object you receive, but you want it to become a string. Consider a DSL like Rake's. One could use:

    task :foo do ...
    
Or

    task 'foo' do ...

Either one is acceptable, and I think it would be overreaching to make people not be able to use a symbol here. 

On the other hand do we want any object to be acceptable? B/c just about every object responds to #to_s. To avoid this, you would end up with something like: (WARNING! Fugly code ahead.)

  def task(name)
    name = (Symbol === name ? name.to_s : name.to_str)
    ...
  end

There has to be a clearer solution than that.

P.S. Just for fun of it I tried this on rake and discovered the Jim decided not to care what get's passed to task. Try this in your Rakefile:

    desc "OMG!"
    task Object.new do
      puts "OMG is right!"
    end

A Duck-typing true beleiver!!! Yea, looks like a bug to me. If the user really needs it they can call #to_s.
=end
----------------------------------------
Feature #7849: Symbol#to_str
https://bugs.ruby-lang.org/issues/7849#change-36318

Author: trans (Thomas Sawyer)
Status: Rejected
Priority: Normal
Assignee: 
Category: core
Target version: next minor


Even though a Symbol is not technically an honest-to-goodness String, from the standpoint of simple practicality it would help to have Symbol#to_str defined.

There are times when we want an argument to accept a String or a Symbol, but don't really want it to accept any type of object under the sun that responds to #to_s --which is just about anything. This is especially the case when writing DSLs. Having Symbol#to_str is the nice solution to this.

Defining Symbol#to_str may be an exception to the rule, but it's one worth making.



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