How Do You Solve “Could not find foobar in any of the sources” after a bundle Command?

Problem scenario
You run a bundle command (e.g., bundle exec foobar create). It fails with an error such as “Could not find foobar in any of the sources”.

What should you do?

Solution
Remove the relevant Gemfile.lock file (e.g., in the directory you are running bundle) if you are allowed to. Are you using a variety of bundle commands?

How Do You Troubleshoot “/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require’: cannot load such file — winrm-elevated (LoadError)”?

Problem scenario
You run a Vagrant command. But you get this message: “/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require’: cannot load such file — winrm-elevated (LoadError)”

What should you do?

Solution
Run this command:

vagrant plugin install winrm-elevated …

How Do You Troubleshoot the Message “/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require’: cannot load such file — foobar (LoadError)”?

Problem scenario
You are running Vagrant, Ruby or a Ruby application, but you get this error: “/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require’: cannot load such file — foobar (LoadError)”

What should you do?

Possible Solution #1
Try to run the original command with “sudo”. If that doesn’t work, use “gem list” to verify “foobar” is installed.

For Windows users, try to run the command or application as Administrator.

How Do You Write a Tic-Tac-Toe Program in Ruby?

Problem scenario
You want to write a Tic-Tac-Toe program in Ruby. What should you do?

Solution

# Tic-tac-toe game in Ruby. Written by continualintegration.com.
# We know Ruby is object-oriented. Ideally we will re-write this to encapsulate all logic in objects.
puts “This is a two player game of tictactoe. One person can pretend to be the other player.”
puts “Both players should share a keyboard and monitor.”
puts “The legend for squares in the grid is as follows: ”
puts ” ”
puts “***************************************************************”
puts “ltc is left-top-corner, …

How Do You Check If a Variable in Ruby Is a Boolean?

Problem scenario
You want to determine if a variable is being assigned a non-string “true” or “false” data type.  That is, you want to distinguish from a string value of true/false and the Boolean, built-in, supported data type of true/false.  Some programming languages support Boolean or bit values.  Ruby has a number of data types.  There is a feature that Ruby supports to test for most of its datatypes.  

How Do You Test If a Variable Is a String or a Numeric Data Type in Ruby?

Problem scenario
You want to test if a given variable is a Numeric or String.  These are built-in data types that Ruby has.

What should you do?

Solution
Append “.is_a? Numeric” or “.is_a? String” to variable.  For an example, here is code that explicitly prints out if the data type is a Numeric or String.

var1 = 123
an = var1.is_a?

Two Error Messages when Installing Gems On Linux

Problem scenario:  You are trying to use gem install, but you get an error like this:
“usr/bin/ruby extconf.rb
mkmf.rb can’t find header files for ruby at /usr/lib/ruby/ruby.h”

Solution:  Install ruby-devel.  For RedHat deriviatives, you can find the rpm here.

=====================================================================================

Problem scenario:  You are running gem install *.gem, and you get ‘ERROR: While executing gem …

Using a rubyntlm script (http.rb), you get “connection refused.”

Problem scenario:  You modify this script to have a hostname, username, and password of a Windows server with IIS installed.  You add a “puts line” stanza on line 32 for debugging.  You try to run the script with ruby http.rb, but you get “connection refused.”  

Possible solutions:  If you changed the port stanza in the http.rb file from 80, make sure there is no firewall blocking the port in the path to the Windows server. 

Rubyntlm: Communication from a Linux Server to a Windows Server

Problem scenario:  You modify this script to have a hostname, username, and password of a Windows server on your network.  You add a “puts line” stanza on line 32.

You run the script but you get a message like this: “HTTP/1.1 404 Not Found error. “

Solution:  Make sure that the Windows server has IIS installed, make sure the server name you entered was correct,