Ruby .gem file add ruby script from directory

Dear forum members
Today I need os module for exe converter that I will develop for ruby.
But I failed to include the os module from a folder into my ruby code.
Thanks in advance for your help.
Note: I downloaded the os module from https://rubygems.org and I’m trying to add it.

Can’t you create a Gemfile and put OS gem as dependency? You can control when to load OS when bundler runs your program…

But if you think that adds inefficiency resulting in use bundler which can slowdown the program startup time by a tiny amount, you may have to tweak the gem a little probably…

EDIT:
Well that was speculation. In a ruby gem, the code is found inside lib directory. If you go inside lib directory of the OS module, you just find one file https://github.com/rdp/os/blob/master/lib/os.rb

[ if you are really talking about this OS gem ]

So it’s dead simple to work with this gem. If the licence permits copying the code, you just copy the os.rb file where your ruby script is, and:

require_relative File.join(__dir__, 'os')

puts %i(
	windows? mac? linux?
	java?
	cpu_count open_file_command
).map { |x| "#{x} => #{OS.send(x)}" }

1 Like

Thanks.

If you use Glimmer DSL for SWT (JRuby desktop development GUI framework) to build desktop apps in JRuby, it automatically includes the OS gem for you. Just follow setup instructions: https://github.com/AndyObtiva/glimmer-dsl-swt#setup

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs