Skip to content

Instantly share code, notes, and snippets.

@joelg
Created May 23, 2010 20:16
Show Gist options
  • Save joelg/411214 to your computer and use it in GitHub Desktop.
Save joelg/411214 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def hello(name)
puts "Hello #{name}"
end
hello("Joel")
@davidjmemmett
Copy link

Is there such thing as constant strings, as in the single-quoted strings in PHP? I know it's a very minor performance gain, but I've never liked PHP's parsing of double-quoted strings.

@joelg
Copy link
Author

joelg commented May 23, 2010

I'm not sure I would say they are "constant strings", but the difference between single-quoted strings and double-quoted strings is that you cannot do string interpolation - "hello $name" with single quotes, you must use concatenation - 'hello '.$name. I'm unsure about performance gains, I would doubt they could be at all significant, unless perhaps you had a VERY large loop! I like to use whatever is most readable, and often if variables are involved then it is double quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment