Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Ruby 1.9 style String interpolation support for lower ruby versions.

#2870

Attached patch adds ruby 1.9 style String interpolation support for lower ruby versions. Thanks to code from Masao Mutoh's GetText gem.

The reason for including this patch is that for I18n we'd like to switch from "{{arg}}" style named arguments to standard ruby 1.9 syntax, i.e. : "%{arg}". This makes later upgrades to ruby 1.9 easier and it makes string interpolation a lot more powerful/flexible than what is currently possible.

Reported by Lawrence Pit · July 6th, 2009 @ 01:34 AM

State: committed
Milestone: 2.x
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: none

Activity

  1. Lawrence Pit
  2. Sven Fuchs
    Sven Fuchs
    • Assigned user set to Jeremy Kemper

    +1 this would make our upgrade path to ruby 1.9 much smoother AND add a ton of flexibility to our interpolation api

    Jeremy, wdyt? :)

    July 6th, 2009 @ 11:38 AM

  3. Repository
    Repository
    • State changed from new to resolved

    (from [da635394c1c3004f4dacf4a35275404e5b1aef43]) Ruby 1.9 style String interpolation support for lower ruby versions. Thanks to code from Masao Mutoh's GetText gem. [#2870 Ruby 1.9 style String interpolation support for lower ruby versions. state:resolved]

    Signed-off-by: Yehuda Katz wycats@yehuda-katzs-macbookpro41.local
    http://github.com/rails/rails/commit/da635394c1c3004f4dacf4a3527540...

    July 8th, 2009 @ 12:22 AM

  4. Sven Fuchs
    Sven Fuchs
    • State changed from resolved to open
    • Tag changed from 3.0, patch to 2-3-stable, 3.0, patch
    • Assigned user changed from Jeremy Kemper to Yehuda Katz (wycats)

    Thanks for applying, Yehuda :)

    Couple of things:

    I noticed the tests don't pass on Ruby 1.9 because Masao's code does not mirror Ruby 1.9's behaviour exactly, but the tests of course specify what the code does. This is true for two situations where Ruby 1.9 raises exceptions while Masao's extension doesn't:

    • Ruby 1.9 raises a KeyError exception for missing named interpolation args (e.g. "%{foo}" % {:bar => :bar})
    • Ruby 1.9 raises an ArgumentError when mixing named and unnamed placeholders (e.g. "%{foo} %f" % [1.0])

    Also, we'll only want to include this code when we're on < Ruby 1.9.

    I'll append a patch that fixes these things and also improves the docs and Rails conventions compliance a little bit.

    After applying this, can you please also BACKPORT this to 2.3-stable? That'd be great :)

    I'll reopen the ticket and assign to Yehuda.

    July 8th, 2009 @ 05:26 PM

  5. Repository
    Repository
    • State changed from open to committed

    (from [17d5cc12b9f8d0d78a081d231e7e0c5ec9df1104]) * don't include String#% for Ruby 1.9 * raise a KeyError exception for missing named interpolation args (like Ruby 1.9 does) * raise an ArgumentError when mixing named and unnamed placeholders (like Ruby 1.9 does) * improve docs and comply a bit more w/ Rails names/conventions

    [#2870 Ruby 1.9 style String interpolation support for lower ruby versions. state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/17d5cc12b9f8d0d78a081d231e7e0c...

    July 18th, 2009 @ 09:11 PM

  6. bingbing