Hi, On Sep 21, 2008, at 8:12 PM, Bernard Kenik wrote: > Thomas B. wrote: >> Thomas Sawyer wrote: >>> Came up with a great little extension today for the Symbol class. >>> One >>> that also shows off Facets' Functor class: >>> >>> require 'facets/functor' >>> >>> class Symbol >>> >>> # Convert symbol to string, apply string method >>> # and convert back to symbol via a fluent >>> # interface. >>> # >>> # :HELLO.re_s.downcase #=> :hello >>> # >>> def re_s >>> @re_s ||= Functor.new do |op, *a| >>> to_s.send(op, *a).to_sym >>> end >>> end >>> >>> end >>> >>> I picked the name 're_s' off the top of my head. I'm open to better >>> suggestions. >>> >>> T. >> >> Nice idea. After some modification (using method_missing) it could be >> used as a temporary patch on Ruby 1.8, as in Ruby 1.9 symbols are >> going >> to respond to most string-like methods. >> >> also T. > > > why not simply use: > > irb(main):002:0> :HELLO.to_s.downcase.to_sym > => :hello What fun is a new version if you can't even re-factor? irb(main):001:0> RUBY_VERSION => "1.9.0" irb(main):002:0> :test.capitalize => :Test A 1.8.x patch needn't rely on Facets, however: class Symbol def method_missing(*args, &block) to_s.__send__(*args, &block).to_sym rescue super(*args, &block) end end Stephen