Since I know almost nothing about Ruby, I'll ask the fedi hivemind for tips...

If I want to start up a Ruby REPL and import 'net/http' so that I can try one request using the latest version of the Gem, what steps should I follow? In Python I'd create a virtualenv and then use 'pip install' to install the package I want - so I assume something similar exists for Ruby. Bonus points if I can do the same thing but intentionally use an older (specific) version of the Gem.

#Ruby #RubyNewbie

@kevin use rbenv and bundler. Search these to get started.

@kevin well if you just want to try it and you have a system ruby, then it's "irb". then require "net/http".

if you want the equivelent of a venv, install rbenv.

@fishidwardrobe @kevin totally. If you just want to try something, no need for virtual environments or packages.
@lkanies @kevin although i should probably point out that net/http is not the friendliest library…
@fishidwardrobe @lkanies As mentioned in another reply, I need to build a reproducer for a bug in Mastodon->Paperclip->Seahorse->net-http, so I don't get to choose the library 🙂

@kevin For managing Ruby versions, either rbenv or the newer rv are fine choices.

With the desired Ruby version installed and active (verify with `ruby -v`), start an interactive Ruby shell with the `irb` command.

Once in an IRB session, `require “net/http”` and the Net::HTTP module should be available.

Do note that Net::HTTP is a bit of a pain to work with. There are a bunch of alternatives, though. I tend to reach for the http gem, but Faraday is also quite popular.

@jgarber In this case I need to use net-http because I'm building a reproducer for a bug in Mastodon->Paperclip->Seahorse->net-http. Thanks for the info!

@kevin Bundler has an inline mode that is great for single scripts (and the REPL, I assume, although I'm not sure I've ever used it like that).

https://guides.rubygems.org/bundler_in_a_single_file_ruby_script/

How to use Bundler in a single-file Ruby script - RubyGems Guides

Tutorials, guides, FAQs for RubyGems package management

Ruby repl with a specific net-http version

Ruby repl with a specific net-http version. GitHub Gist: instantly share code, notes, and snippets.

Gist
@kevin people already gave you all the answers, but let me add you can load net/http directly when starting the repl like irb -r net/http