T
Trans
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.
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.