mokayode mokayode - 11 months ago 35
Ruby Question

Is Socket bundled with Pry?

I'm learning socket in Ruby. I tried

require 'socket'
in a Pry session only to get
. After much trouble, I decided to use
but things worked fine.

Later, I ran'localhost', 2000)
in a pry session without requiring
and it worked!

I'm curious as to why it's so. Is it that
is already part of pry? I checked Pry source code but could not figure it out.

Pry version 0.10.3 on Ruby 2.3.0


Yes socket is loaded in Pry when it starts. Whereas irb does not load it initially. You can always tells if a file has already been loaded because require will return false, as opposed to a LoadError.

2.3.1 :001 > require 'socket' # not yet loaded
# => true 
2.3.1 :002 > require 'socket' # already loaded
# => false 
2.3.1 :003 > require 'not_a_file' # error because it does not exist
# LoadError: cannot load such file -- not_a_file