As an update about gems, I seem to have fallen in love with https://rubygems.org/gems/celes I have also put a little of my own C extensions into Eot gem now.
http://www.rubydoc.info/gems/equationoftime/4.1.8
now uses Celes.
http://www.rubydoc.info/gems/celes
You asked for Ruby. You got it.
For other ways try links like http://www.die.net/moon/ or http://www.die.net/earth/
The related link Sunrise / set calculations does components very similar to this ruby gem only is in python. You will see the zenith starts for the different solar events in this question which is a good one. If I look in my local newspaper for these events, which one is it? (astronomical, nautical, civil, official) Official right?
For definitions on twilight see http://aa.usno.navy.mil/faq/docs/RST_defs.php
If you want to see some experimental code that was inspired by this formula http://en.wikipedia.org/wiki/Sunrise_equation
I played around with that in Ruby. see https://github.com/DouglasAllen/Gather_the_gists/blob/master/suntimes_no_gem.rb
I have AstroCpp saved at https://github.com/DouglasAllen/C_Programming_Refference/tree/master/examples_src
The link for it is http://projectpluto.com/source.htm
I like Ruby-Shere too and is an older gem not on github but on sourceforge. http://sourceforge.net/projects/ruby-sphere/
I used Mike's software and it seems to prove itself. He doesn't tell you how it all fits together but it's good code to work with. https://github.com/mikereedell/sunrisesunset-ruby http://www.mikereedell.com/
I have a web site with lots of links at http://equationoftime.herokuapp.com/links
Some code will calculate the Right Ascension of the Sun and that means it will be on your local merridian at that time sidereal. So you will have to convert that back to your time zone for your Solar Transit time then just find the event horizon angles, divide the total by 2 and add or subtract that from your solar transit which is your local longitude. But that is where equation of time comes into play. It's not always right there. The angle is different as the year progresses. So that not only effects your sundial readings but the sunrise and sunset times.