String#% and a Hash

  • Thread starter Daniel Brumbaugh Keeney
  • Start date
D

Daniel Brumbaugh Keeney

Ruby1.9 doesn't seem to accept hashes in the String#% method anymore.
I use this a lot in conjunction with gettext[1], and am basically
wondering if this is a language change or a 1.9 bug. It doesn't appear
to be documented in Ruby1.8 or Ruby1.9. Thanks.

Daniel Brumbaugh Keeney

[1]
<http://www.yotabanana.com/hiki/ruby-gettext.html>
 
M

MonkeeSage

Ruby1.9 doesn't seem to accept hashes in the String#% method anymore.
I use this a lot in conjunction with gettext[1], and am basically
wondering if this is a language change or a 1.9 bug. It doesn't appear
to be documented in Ruby1.8 or Ruby1.9. Thanks.

Daniel Brumbaugh Keeney

[1]
<http://www.yotabanana.com/hiki/ruby-gettext.html>

Example? In 1.8.6, this excepts:

"blah %s %s" % {:a=>"blah", :b=>"blah"}

# => ArgumentError: too few arguments ...

Regards,
Jordan
 
R

Ryan Davis

Ruby1.9 doesn't seem to accept hashes in the String#% method anymore.
I use this a lot in conjunction with gettext[1], and am basically
wondering if this is a language change or a 1.9 bug. It doesn't appear
to be documented in Ruby1.8 or Ruby1.9. Thanks.

Did it ever? I think you're referring to this, right?
Also you can write as:
_("%{filename} was not found") % {:filename => "foo.rb"}
_("%{filename1} and %{filename2} is not same file") % {:filename1 =>
"foo.rb",
:filename2 =>
"bar.rb"}
_("%{filename} is %{filesize} byte") % {:filename => "foo.rb",
:filesize => 100}

that looks like a gettext extension of String#%, not part of 1.8 core:
ArgumentError: malformed format string - %{
from (irb):8:in `%'
from (irb):8

I know it works this way in python, and it is actually pretty nice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top