HTTPS clone URL
Subversion checkout URL
Ruby Talk FAQ
Clone this wiki locally
Welcome to the list of Frequently Asked Questions on the ruby-talk mailing list ! Feel free to add to it!
What are the ruby-talk best practices/guidelines?
How do I convert a ruby script into a distributable executable?
What is the best Ruby GUI framework?
What is the best editor for Ruby?
Ruby should do X!
Why does ruby’s comparison with floats fail?
- You will most likely get a more qualified response from the project-specific mailing lists or forums than on the ruby-talk mailing list. The ruby-talk mailing list focuses on the Ruby programming language itself. Check the projects homepage for details about where to get help.
- Ocra is often recommended for Windows users 1
- The older way is “rubyscript2exe”, but this project is not updated for newer Ruby versions.
- exerb is also another windows packager.
- All the cross platform ones also work with doze.
- “crate” is cross platform (and often recommended for linux) [1 2].
- rawr is a distributor for jruby.
- Source code: If you just wish to distribute your ruby code to other developers then you could also distribute it as a gem.
- Shoes (somewhat unmaintained GUI framework) allows packaging distributables for each OS.
- Ruby Installer is the successor to the One-Click Installer. Release candidates of newer Ruby versions are available for download. While they are not directly compatible with the old One-Click Installer, they are generally stable for most uses.
here is a list comparing some
- See the Ruby GUI comparison
- Please read this post for an intro to writing RCR’s. I would note that the latest way to submit an RCR is to just submit it to the ruby-core mailing list and/or create a RedMine ticket. Typically I would recommend discussing it on ruby-talk first, as well.
Instructions on how to submit a patch
- See Closures in Ruby
Sometimes floats in Ruby do funky things.
Example of odd behavior:
>> (2.0-1.1) == 0.9 => false
Why? Because floats are by default slightly imprecise
This is not Ruby’s fault, but floating point numbers in general suffer from this type of rounding error, because they’re limited to x number of bytes, and, in general, cannot store decimal number perfectly.
>> 1.1 => 1.1 > 0.9 => 0.9 > 1.1-0.9 => 0.20000000000000007
Your options when you run into this:
- compare values by delta, example (from test/unit framework):
assert_in_delta((1.1-0.9), 0.2, 0.0001) # passes
- use BigDecimal
>> require 'bigdecimal' >> (BigDecimal.new("1.1") - BigDecimal.new("0.9")) == 0.2 => true
- use Rational
>> Rational(11, 10) - Rational(9, 10) # 11/10 - 9/10 => (1/5) >> _ == 0.2 => true
How can I make them pretty (and misleading) again, in 1.9.2+ like they used to be?
class Float def pretty_s num = "%.12f" % self num =~ /\..*?(0+)$/ num.sub!($1, '') # might be like 2. at this point num = num[0..-2] if num[-1] == '.' num end end p 1.1-0.9 # >> 0.20000000000000007 p (1.1-0.9).pretty_s >> "0.2" p 2.0.pretty_s >> "2"
With 1.9.0 and 1.9.1, gem uses “gem_prelude” to load files from gems. This sped things up quite a bit for startup time, but introduced a few subtle bugs with rubygems so was basically set to be used far less in 1.9.2. It basically loaded the “lib” paths of each highest numbered gem to the require path.
In 1.9.2, if you ever do a
require 'rubygems' it reverts back to the normal “full” rubygems. In 1.9.1 it reverts to “full” rubygems if you ever use a gem specific constant or method, like
In 1.9.1, if you want to avoid using the somewhat buggy gem_prelude, then run your script like
ruby --disable-gems script_name.rb and include the
require 'rubygems' line in your script, or upgrade to 1.9.2
Note: this is not the first ruby faq. Take a step back in history and see the original