Learn Ruby

Ruby is modern and extremely capable programming language, and it runs many leading websites.

Ruby is a quite useful for the simulations on this site. It is an easy language to learn and write, and its code is clean and very readible. Since many web applications are developed in Ruby, your simulations will be relatively easy to concert into web applications.

EXTERNAL RESOURCES TO THOSE WHO ARE NEW TO PROGRAMMING OR WHO WANT MORE DETAIL.
FAST START

If you are familiar with programming and use *nix, you can probably get started with the following steps:

  1. To see if you have the correct version of Ruby installed, in the command line interface, enter: ruby -v
  2. If the version is at least 1.9.2, you are fine. Otherwise you will need to install a more recent version.
  3. Download the following file: hello_world.rb
  4. Run the file by going to the directory where it is located and entering: ruby hello_world.rb
  5. “Hello World!” should be outputted. Try to change the output text in a text editor, and run it again.
  6. Download the following file: simplesim.rb
  7. Run that program. Then view the source code in a text editor. If you understand this, it is enough to get started.
  8. Note that in Ruby, everything is an object. E.g. appending “.to_s” to a variable accesses certain object attributes.
A SIMPLE PROGRAM

This paper discusses a simple Ruby program that you can use to generate exponential growth. There is a very simple program that introduces variables and loops. Then there is a slightly more advanced one that shows string formatting. This is a good program to practice with before studying more advanced ones.

MORE ADVANCED CAPABILITIES

Other programs on this site will involved more advanced capabilities that will prove to be very useful.

  • The Fourier Hear Conduction Law program introduces the math library and the if/elsif conditional statement, and is a good place to start learning about thermodynamics.
  • The Carnot Engine program provides additional experience working with calculations.
  • The Newton’s Law of Cooling program introduces command line user input, as well as data output files which you can then import into graphing programs.
  • Other programs will demonstrate objects that represent engines and reservoirs. An object is useful in that you can set it up once, then create many instances of it without all of the set-up work each time.

One thought on “Learn Ruby

  1. Pingback: News from the 2015 AHA Annual Meeting | HistoryQuant

Leave a Reply