Can I import/require OpenStudio SDK (Ruby bindings) into IRB?
Yes? No? What's the secret handshake?
First time here? Check out the Help page!
Yes? No? What's the secret handshake?
Yeah; I have an environment variable path set to C:\Program Files\OpenStudio 1.10.0\ruby-install\ruby\bin
, and can require 'openstudio'
from within irb to access the SDK.
...I think there are additional steps if you're not using the ruby that's shipped with OS. See the 'Optional - Install Ruby' subsection of 'Installation Steps' on this page.
Thanks! For those who care, the MacOS magic is export PATH="/Applications/OpenStudio 1.10.0/Ruby:$PATH"
. Works with Ruby/IRB that ships with MacOS also.
As Kyle mentioned, there is a way to customize the irb startup configuration. You have to do the following (assuming Mac or Linux):
If ~/.irbrc
does not exist, call touch ~/.irbrc
to create it.
Then inside ~/.irbrc
you can put
// I think this is the correct pathing
require "/Applications/OpenStudio 1.10.0/Ruby/openstudio.rb"
require 'irb/completion'
or what I have in my ~/.irbrc
file (other than different openstudio.rb path for my dev build)
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] = [] unless IRB.conf.key?(:LOAD_MODULES)
unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
IRB.conf[:LOAD_MODULES] << 'irb/completion'
end
require "/Applications/OpenStudio 1.10.0/Ruby/openstudio.rb"
This will automatically load completion and openstudio everytime you call irb
on command line.
I specify the paths on the command line like this (on Windows for version 1.10.0):
C:\Users\jdegraw>"C:\Program Files\OpenStudio 1.10.0\ruby-install\ruby\bin\irb" -I "C:\Program Files\OpenStudio 1.10.0\Ruby\openstudio"
I like doing it this way because it also works for my development build if I change out the paths.
Again, irb -I /Applications/OpenStudio 1.10.0/Ruby
for enlightened Mac users.
another little gem. In Ruby 2.0 and beyond, at least on Mac, irb completion stopped being loaded by default. The first thing I always do after require 'openstudio'
is require 'irb/completion'
. Then your tab completion will work.
@Kyle Benne It is also apparently true on Windows. Thanks for pointing this out, was beginning to think something was wrong with my tab key.
I'm pretty sure there is a way to customize irb's startup environment but I never bothered to look into it.
RubyMine (mac and windows) lets you change what version of ruby you use under the run configuration.
For the sake of using the official documentation out there, specifically the "Getting Started" tutorial:
Optional - Install Ruby If you plan to use the OpenStudio SDK Ruby bindings via command prompt on Windows, you must install Ruby. OS X already has Ruby installed.
Download the Ruby 2.0.0 installer. If you have the Windows (x64) version of OpenStudio (Help>About>Compiler shows Visual Studio 12 2013 Win64), you'll need the x64 Ruby installer. If you have the Windows (x32) version of OpenStudio, you'll need the non-x64 Ruby installer.
Add `C:\Ruby200\bin` (or wherever you installed Ruby) to the PATH environment variable. Detailed instructions.
Create a text file with the following text inside:
`require 'C:\Program Files (x86)\OpenStudio 1.7.0\Ruby\openstudio.rb'`
Save the file as `openstudio.rb` here: `C:\Ruby200\lib\ruby\site_ruby\openstudio.rb` (next to the 2.0.0 folder).
Test your installation by opening a command prompt and typing: irb ENTER. Then, type require 'openstudio ENTER. If you see some QSslSocket messages and => true, it's working.
I personally have several of these files in there, usually two: openstudio.rb
which points to the latest stable release, and openstudio-rc.rb
which points to a release candidate. This way I can require any of these two as needed.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2016-01-22 13:15:43 -0600
Seen: 486 times
Last updated: Jan 25 '16
If you can get IRuby to work on your machine that would be my suggestion for a more pleasant IPython-like experience to IRB.