Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created February 9, 2011 06:41
Show Gist options
  • Save jordansissel/818052 to your computer and use it in GitHub Desktop.
Save jordansissel/818052 to your computer and use it in GitHub Desktop.
Stuff that didn't need to change between ruby 1.8 and 1.9

This DateTime#sec_fraction change is not documented as far as I can tell, at time of writing (2011/02/08).

The change is that sec_fraction in 1.8.x returns "fraction of a day" where in 1.9.x it returns "fraction of a second"

snack(~) % rvm ruby -e 'require "date"; p [RUBY_VERSION, RUBY_PLATFORM] => DateTime.now.sec_fraction.to_f' | sort           
{["1.8.6", "x86_64-linux"]=>3.69974537037037e-06}
{["1.8.7", "java"]=>5.72916666666667e-06}
{["1.8.7", "x86_64-linux"]=>2.9518287037037e-06}
{["1.8.7", "x86_64-linux"]=>6.3940162037037e-06}
{["1.9.1", "x86_64-linux"]=>0.924744134}
{["1.9.2", "x86_64-linux"]=>0.750296812}

In the Ruby 1.9.2 ChangeLog, I could find no mention of 'sec_fraction' and all mentions of DateTime do not cover this behavior change.

http://svn.ruby-lang.org/repos/ruby/tags/v1_9_2_0/ChangeLog

String#[NUMBER] returns a number in 1.8.x and a string in 1.9.x

snack(~) % rvm ruby -e 'p [RUBY_VERSION, RUBY_PLATFORM] => "hello"[3]' | sort
{["1.8.6", "x86_64-linux"]=>108}
{["1.8.7", "java"]=>108}
{["1.8.7", "x86_64-linux"]=>108}
{["1.8.7", "x86_64-linux"]=>108}
{["1.9.1", "x86_64-linux"]=>"l"}
{["1.9.2", "x86_64-linux"]=>"l"}

I could not find this documented in the Ruby 1.9.2 ChangeLog. http://svn.ruby-lang.org/repos/ruby/tags/v1_9_2_0/ChangeLog

I saw anecdotes about other changes required because of this undocumented change, but nothing specifically saying "We broke String#[], here is the new behavior" - examples of transitive changes:

Thu Jan 29 13:16:11 2009  Nobuyoshi Nakada  <nobu@ruby-lang.org>

  * lib/securerandom.rb (SecureRandom.uuid): uses unpacked array
    instead of string, because String#[] returns one length string.

Sat Sep  2 12:00:32 2006  NAKAMURA, Hiroshi  <nahi@ruby-lang.org>

  * lib/csv.rb (CSV::IOReader#initialize): use String#[](pos, len)
    instead of String#[](idx) to check utf BOM.  follows String#[](idx)
    behavior change of 1.9.

Sat Jun 10 10:13:13 2006  NAKAMURA Usaku  <usa@ruby-lang.org>

  * lib/rdoc/markup/simple_markup/inline.rb: follow the new behavior
    of String#[].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment