Noob Concatenation Q?

Can someone briefly explain why ::
puts i.to_s +" :: "+arrayoutput[i]

yaml.rb:12: undefined method [email protected]' for " :: ":String (NoMethodError) from F:/RUBY/Source/yaml.rb:11:intimes’
from F:/RUBY/Source/yaml.rb:11

but the addition of a space => puts i.to_s + " :: "+arrayoutput[i]
results in success.

some proir exp in java and cant remember requiring spaces in
concatentation. any replies welcomed!


Posted with NewsLeecher v3.8 Beta 6
Web @ http://www.newsleecher.com/?usenet


[email protected] wrote:

Can someone briefly explain why ::
puts i.to_s +" :: "+arrayoutput[i]

yaml.rb:12: undefined method [email protected]' for " :: ":String (NoMethodError) from F:/RUBY/Source/yaml.rb:11:intimes’
from F:/RUBY/Source/yaml.rb:11

because parens in Ruby are optional, so it ends up:

puts i.to_s(+" :: "+arrayoutput[i])

lopex

On May 4, 3:54 pm, [email protected] ([email protected]) wrote:

some proir exp in java and cant remember requiring spaces in
concatentation. any replies welcomed!


Posted with NewsLeecher v3.8 Beta 6
Web @http://www.newsleecher.com/?usenet


I know I’m not answering your question, but
I think this is cleaner:

puts “#{ i } :: #{ array_output[i] }”

On 5/4/07, Marcin Miel¿yñski [email protected] wrote:

puts i.to_s(+" :: "+arrayoutput[i])

Correct and then the + in
+"::"

is being interpreted by the parser as a unary + which it implements by
sending the message :[email protected] to the string “::”.

$ qri [email protected]
------------------------------------------------------------- Numeric#[email protected]
+num => num

 Unary Plus---Returns the receiver's value.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs