On Jun 20, 2012, at 15:25 , Hal F. wrote:
(name.to_s << "=").to_sym
:"#{name}="
On Jun 20, 2012, at 15:25 , Hal F. wrote:
(name.to_s << "=").to_sym
:"#{name}="
On 06/20/2012 05:25 PM, Hal F. wrote:
From what I've seen, the most frequently voiced desire is to be able to (name.to_s << "=").to_sym
With regard to metaprogramming, perhaps the problem could be better
solved by allowing the things that currently consume only symbols to
also consume strings or really anything that provides a to_sym method.
That would also better follow the notion of duck typing. I’m not sure
if this would help you in your particular case very much though.
I haven’t heard any arguments for or against such an approach before.
As long as the related documentation was clear about the requirement of
a to_sym implementation that returns a Symbol instance, this wouldn’t
appear to be a problem right off (… he says naively…).
-Jeremy
Ryan D. wrote in post #1065463:
On Jun 20, 2012, at 15:25 , Hal F. wrote:
(name.to_s << "=").to_sym
:"#{name}="
By the way :
In Sequel, you have to write something like ‘.order(:name.desc)’ to ask
for a reverse ordering of a field. How, given the symbol :name, do you
build the symbol :name.desc, without some sort of ‘eval’ ?
_md
Alex C. wrote in post #1065959:
As I understand it, interpolation is not eval, so you answered your own
question (or at least included it).:"#{name}.desc"
ymmv since my iPhone doesn’t run ruby
True ! Sorry !!
_md
Michel D. wrote in post #1065964:
Alex C. wrote in post #1065959:
As I understand it, interpolation is not eval, so you answered your own
question (or at least included it).:"#{name}.desc"
ymmv since my iPhone doesn’t run ruby
True ! Sorry !!
_md
Checked again. This does not work with a dot in the string :
:“name” => :name
:“name.desc” => :“name.desc”
_md
As I understand it, interpolation is not eval, so you answered your own
question (or at least included it).
:"#{name}.desc"
ymmv since my iPhone doesn’t run ruby
On Jun 25, 2012, at 08:14 , Michel D. wrote:
In Sequel, you have to write something like ‘.order(:name.desc)’ to ask
for a reverse ordering of a field. How, given the symbol :name, do you
build the symbol :name.desc, without some sort of ‘eval’ ?
You’ve already gotten a good answer (Symbol#desc) but I wanted to add
some clarification on how your example above is seen by ruby:
3431 % pwd
/Users/ryan/Work/p4/zss/src/ruby_parser/dev/
3432 % rake debug R=“a.order(:name.desc)”
s(:call, s(:call, nil, :a), :order, s(:call, s(:lit, :name), :desc))
-------------------------------
2012/6/25 Michel D. [email protected]:
By the way :
In Sequel, you have to write something like ‘.order(:name.desc)’ to ask
for a reverse ordering of a field. How, given the symbol :name, do you
build the symbol :name.desc, without some sort of ‘eval’ ?
I think Sequel defines the method #desc on Symbol to make this work.
– Matma R.
Ryan D. wrote in post #1066026:
On Jun 25, 2012, at 08:14 , Michel D. wrote:
In Sequel, you have to write something like ‘.order(:name.desc)’ to ask
for a reverse ordering of a field. How, given the symbol :name, do you
build the symbol :name.desc, without some sort of ‘eval’ ?You’ve already gotten a good answer (Symbol#desc) but I wanted to add
some clarification on how your example above is seen by ruby:3431 % pwd
/Users/ryan/Work/p4/zss/src/ruby_parser/dev/
3432 % rake debug R=“a.order(:name.desc)”
s(:call, s(:call, nil, :a), :order, s(:call, s(:lit, :name), :desc))
-------------------------------
Thanks, Ryan and Bartosz, for your help !
_md
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs