Bang methods (Exclamation point at the end of the method name) There are methods that have a permanent or dangerous version. The exclamation point designates to use the dangerous version of the method. String manipulation The bang versions of the string manipulation methods (with the exclamation point), modify the string variable in place. Some of these methods …
Category Archives: Ruby
`pwd’: No such file or directory – getcwd (Errno::ENOENT)
When you rename a subdirectory under the directory where your Linux or MacOS terminal is open you may get the error message /opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.4.19/lib/chef/knife/cookbook_download.rb:45:in `pwd’: No such file or directory – getcwd (Errno::ENOENT) You need to refresh the directory cache of the terminal. Go one level higher cd .. Go back to the directory cd MY_DIRECTORY …
Continue reading “`pwd’: No such file or directory – getcwd (Errno::ENOENT)”
Ruby Gem Management
Ruby gems are Ruby programs and libraries with a name, version and the platform that can execute them. List the installed gems on your system gem list Detailed list that includes the author, homepage, license, install location and a short description gem list -d Install the latest version of the gem gem install GEM_NAME Install a …
Undefined method or attribute error in a Chef recipe
There are multiple reasons Chef can display the following error message NoMethodError ————- Undefined method or attribute `…’ on `node’ There are many ways to reference an attribute in a Chef recipe: node[‘ATTRIBUTE_NAME’] (the recommended style) node[“ATTRIBUTE_NAME”] node[:ATTRIBUTE_NAME] (use it only if the single or double quotes (‘ or “) would cause a problem …
Continue reading “Undefined method or attribute error in a Chef recipe”
Generate a GUID in Chef with Ruby
When you need a unique string to name a resource in your Chef scrip, generate a GUID with SecureRandom.uuid To make sure the resource always gets a unique name: log “#{SecureRandom.uuid}” do message ‘My message’ level :info end
Last characters of a string in Ruby
To get the last characters of a string in Ruby, use the following instructions. If the string is shorter than the selected number of characters, the entire string is returned. a = ‘12345’ b = a[-3..-1] || a puts b Returns 345