%w for symbols

J

Joel VanderWerf

Ara.T.Howard said:
i don't think it would be a problem for symbols either since you could
never
really need to do

obj.send 'hi there'.intern

since you could never define

def hi there
42
end

Wellll...

irb(main):001:0> class A
irb(main):002:1> define_method "hi there" do puts "Hi, there!"; end
irb(main):003:1> end
=> #<Proc:0x40208870@(irb):2>
irb(main):004:0> A.new.send "hi there"
Hi, there!
 
M

Mark Hubbart

we are already down that path

jib:~ > ruby -r yaml -e 'y %w(abc hi there)'
---
- abc
- hi
- there

eg. there is not %w equivalent of ["abc", "hi there"] and this has
not been a
problem.

This was mentioned elsewhere on this thread, I believe:

%w(abc hi\ there)
==>["abc", "hi there"]
and you could never need

hash['hi there'.intern]

since you could not type

hash[:hi there]

hash[:"hi there"]

I've used symbols with embedded spaces before, in hashes. It seems odd
to use them in method names, but as someone else pointed out, it does
work...

cheers,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top