Close

ruby

gem – trollop

trollop lets you easily create script parameters with meaningful names, instead of useing ARGV[0], ARGV[1],…etc. If you have the following in your ruby script: cat ./testscript.rb #!/usr/bin/env ruby require ‘trollop’ opts = Trollop::options do opt :hostname, “Server FQDN.”, :type => :string end puts opts[:hostname] Next we install the gem: $ […]

Read More

gem – yaml

Yaml actually comes as part of the ruby core, therefore there is no ruby gem for it. Lets say you have the following yaml file: $ cat /etc/credentials.yaml — :foreman: :username: ‘codingbee’ :password: ‘liverpool’ now you want use these content, then you do: cat yamldemo.rb require ‘yaml’ credentials = YAML.load_file(“/etc/credentials.yaml”) […]

Read More

Ruby – A hello world ruby script example

$ cat testscript.rb #!/usr/bin/env ruby a_string = “Hello World!” puts a_string puts a_string.class The first line is slightly unusual because: https://en.wikibooks.org/wiki/Ruby_Programming/Hello_world#Using_env Next make it an executable: $ chmod 777 testscript.rb then run the script: $ ./testscript.rb Hello World! String

Read More

RVM – Deleting a Ruby version

Any gems that you install while using an RVM’s ruby version, is self contained in that version. However there may come a time when you no longer want to use a particular ruby version and want to delete it along with all it’s gems. Then this can be done using […]

Read More

RVM – Using rvmsudo instead of sudo

There are times when you need to run a ruby related command to install something, e.g. “bundle install” or “gem install gem-name”. If you are an rvm managed ruby version, then it is bad/messy practice to do this. because doing so will install the gem system-wide, rather then ruby version […]

Read More

RVM – Installing a version of ruby

You are now ready to install a version of ruby to run on top of RMV. Before you install any new version of ruby to run on top of rvm, let’s first confirm that there are no versions of ruby running on top of rvm to begin with: [sher@puppetmaster ~]$ […]

Read More

Ruby – Environment Variable

You can read all the environment variables via the irb using the “ENV” command: irb(main):231:0* puts ENV.sort COLUMNS 188 HISTCONTROL ignoredups HISTSIZE 1000 HOME /root HOSTNAME puppetmaster.local LANG en_GB.UTF-8 . . …etc Here the keys are in capital and the values are in string. Alternatively we could use “pretty print” […]

Read More