Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ruby let me use #$$ to print the PID in a string?

Tags:

ruby

pid

I was looking at some code examples and I came across this line:

puts "child #$$ accepting..."

which outputs

>> child 7231 accepting...

It looks like $$ is the PID and it's leveraging some shorthand for the normal #{$$} string interpolation syntax. I can't find the documentation for this though. I'm curious what other short hand tricks are available (or going to confuse me).

Where are the docs? Why is this special?

like image 906
Dane O'Connor Avatar asked Aug 17 '12 15:08

Dane O'Connor


People also ask

What is let in Ruby?

Use let to define a memoized helper method. The value will be cached across multiple calls in the same example but not across examples. Note that let is lazy-evaluated: it is not evaluated until the first time the method it defines is invoked.

What is the difference between let and let RSpec?

(:let) is lazily evaluated and will never be instantiated if you don't call it, while (:let!) is forcefully evaluated before each method call.

What is Ruby RSpec?

RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.


1 Answers

Ruby allows you to omit the braces for global ($var), instance (@var), and class (@@var) variables when doing string interpolation.

like image 167
Reese Moore Avatar answered Oct 11 '22 02:10

Reese Moore