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?
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.
(:let) is lazily evaluated and will never be instantiated if you don't call it, while (:let!) is forcefully evaluated before each method call.
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.
Ruby allows you to omit the braces for global ($var
), instance (@var
), and class (@@var
) variables when doing string interpolation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With