First time here? Check out the Help page!

Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
5

Can I import/require OpenStudio SDK (Ruby bindings) into IRB?

asked 9 years ago

Yes? No? What's the secret handshake?

Preview: (hide)

Comments

If you can get IRuby to work on your machine that would be my suggestion for a more pleasant IPython-like experience to IRB.

MatthewSteen's avatar MatthewSteen  ( 9 years ago )

4 Answers

Sort by » oldest newest most voted
2

answered 9 years ago

updated 9 years ago

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.

Preview: (hide)
link

Comments

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.

__AmirRoth__'s avatar __AmirRoth__  ( 9 years ago )
3

answered 9 years ago

updated 9 years ago

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.

Preview: (hide)
link

Comments

That's cool, thanks Mark!

macumber's avatar macumber  ( 9 years ago )
2

answered 9 years ago

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.

Preview: (hide)
link

Comments

Again, irb -I /Applications/OpenStudio 1.10.0/Ruby for enlightened Mac users.

__AmirRoth__'s avatar __AmirRoth__  ( 9 years ago )

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's avatar Kyle Benne  ( 9 years ago )

@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.

Jason DeGraw's avatar Jason DeGraw  ( 9 years ago )

I'm pretty sure there is a way to customize irb's startup environment but I never bothered to look into it.

Kyle Benne's avatar Kyle Benne  ( 9 years ago )

RubyMine (mac and windows) lets you change what version of ruby you use under the run configuration.

David Goldwasser's avatar David Goldwasser  ( 9 years ago )
1

answered 9 years ago

updated 9 years ago

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.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

2 followers

Stats

Asked: 9 years ago

Seen: 514 times

Last updated: Jan 25 '16