Latest Pre-release in branch 2.0
2.0.0-p648
Released 16 Dec 2015
(10 years ago)
SoftwareRuby
Version2.0
Status
End of life
Initial release2.0.0
24 Feb 2013
(13 years ago)
Latest release2.0.0-p648
16 Dec 2015
(10 years ago)
End of bug fixes24 Feb 2016
(Ended 10 years, 3 months ago)
End of life24 Feb 2016
(Ended 10 years, 3 months ago)
Release notes https://ruby-lang.org/en/news/2015/12/16/ruby-2-0-0-p648-released/
Source codehttps://github.com/ruby/ruby/tree/v2_0_0-p648
Documentationhttps://ruby-doc.org
Downloadhttps://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p648.tar.gz
Ruby 2.0 ReleasesView full list

What Is New in Ruby 2.0

Ruby 2.0 introduced significant language refinements and performance enhancements. This release focused on making Ruby more expressive and efficient for developers.

Category Key Changes
New Features Keyword Arguments, Module#prepend, Refinements, %i for symbol arrays, default UTF-8 encoding
Performance Faster require, lazy symbol garbage collection, optimized VM and GC
Deprecations Ruby 1.8.7 support, $SAFE=4, some legacy features
Libraries New and updated standard libraries

How did keyword arguments improve method definitions?

Keyword arguments are a major syntax upgrade in Ruby 2.0. They allow defining methods with named parameters, making method calls clearer and more self-documenting.

You can define required and optional keyword arguments, which eliminates the need for parsing a final options hash. This makes APIs much more intuitive to use.

Example

def establish_connection(host:, port: 3306, ssl: false)
  # Method body
end

# Clear, explicit call
establish_connection(host: "db.example.com", ssl: true)

What is the purpose of Module#prepend?

Module#prepend provides a new way to mix modules into a class that takes precedence over the class's own methods. It inserts the module before the class in the ancestor chain.

This is powerful for overriding methods while still having access to the original implementation via super. It's a cleaner alternative to alias_method_chain patterns used in earlier versions.

Example

module Logging
  def execute
    puts "Starting..."
    super
  end
end

class Worker
  prepend Logging
  def execute
    # Actual work
  end
end

How do refinements change monkey-patching?

Refinements offer a scoped and controlled alternative to global monkey-patching. They allow you to modify classes within a specific module or file scope without affecting the entire application.

This addresses a major pain point in large codebases where conflicting monkey patches could cause subtle bugs. You activate refinements with the using keyword within a module or at the top of a file.

Example

module StringRefinements
  refine String do
    def shout
      upcase + "!"
    end
  end
end

# Only active within this module
module MyModule
  using StringRefinements
  "hello".shout # => "HELLO!"
end

What performance enhancements were included?

Ruby 2.0 brought several under-the-hood performance improvements. The virtual machine and garbage collector were optimized for better execution speed and memory usage.

Lazy symbol garbage collection helps with memory consumption in long-running processes. The require method also became faster, reducing application boot time.

What syntax shortcuts were added?

New literal syntaxes made code more concise. The %i notation creates arrays of symbols without needing multiple quotes and colons.

Default source encoding was changed to UTF-8, eliminating the need for magic comments in most files. This reflects Ruby's modern, international use cases.

Example

# Old way
symbols = [:foo, :bar, :baz]

# New in Ruby 2.0
symbols = %i(foo bar baz)

FAQ

Are keyword arguments backward compatible with old option hash patterns?
Yes, Ruby maintains backward compatibility. Methods defined with traditional option hashes can still be called with keyword arguments, and vice versa in most cases.

When should I use prepend versus include?
Use prepend when you need your module's methods to override the class methods. Use include when you want the class methods to take precedence over the module's methods.

Do refinements completely solve monkey-patching problems?
They help significantly by containing changes to specific scopes, but they're not a silver bullet. The using keyword's lexical scope can sometimes be surprising in complex codebases.

What happened to Ruby 1.8.7 support?
Ruby 2.0 dropped support for version 1.8.7. This was a major cleanup that allowed removal of legacy code and adoption of modern features.

Is the UTF-8 default encoding applied to all files?
Yes, source files are interpreted as UTF-8 by default unless you specify otherwise with a magic comment. This simplifies working with international characters.

Releases In Branch 2.0

VersionRelease date
2.0.0-p64816 Dec 2015
(10 years ago)
2.0.0-p64718 Aug 2015
(10 years ago)
2.0.0-p64513 Apr 2015
(11 years ago)
2.0.0-p64325 Feb 2015
(11 years ago)
2.0.0-p59813 Nov 2014
(11 years ago)
2.0.0-p59427 Oct 2014
(11 years ago)
2.0.0-p57619 Sep 2014
(11 years ago)
2.0.0-p48109 May 2014
(12 years ago)
2.0.0-p45124 Feb 2014
(12 years ago)
2.0.0-p35322 Nov 2013
(12 years ago)
2.0.0-p24727 Jun 2013
(12 years ago)
2.0.0-p19514 May 2013
(13 years ago)
2.0.024 Feb 2013
(13 years ago)
2.0.0-rc208 Feb 2013
(13 years ago)