# String#% and a Hash

**URL:** <https://www.ruby-forum.com/t/string-and-a-hash/124625>\
**Category:** Ruby\
**Created:** [December 31, 2007, 8:35am UTC](https://www.ruby-forum.com/t/string-and-a-hash/124625 "2007-12-31T08:35:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [December 31, 2007, 8:35am UTC](https://www.ruby-forum.com/t/string-and-a-hash/124625/1 "2007-12-31T08:35:50Z")

</div>

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 K.

[1]  
[http://www.yotabanana.com/hiki/ruby-gettext.html](http://www.yotabanana.com/hiki/ruby-gettext.html)

---

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [December 31, 2007, 8:45am UTC](https://www.ruby-forum.com/t/string-and-a-hash/124625/2 "2007-12-31T08:45:46Z")

</div>

On Dec 31, 1:34 am, Daniel Brumbaugh K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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 K.
> 
> [1]  
> [http://www.yotabanana.com/hiki/ruby-gettext.html](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

---

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [December 31, 2007, 9:11am UTC](https://www.ruby-forum.com/t/string-and-a-hash/124625/3 "2007-12-31T09:11:28Z")

</div>

On Dec 30, 2007, at 23:34 , Daniel Brumbaugh K. wrote:

> 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:

> > > s = ‘%{a}’; s.%(“a” =\> 42)  
> > > 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.
