small medium large xlarge

1-e9eaef6efa5c32ae_pragsmall
12 Apr 2009, 20:02
Klaus Breyer (1 post)

I try the little example application for the different length of strings in unicode.

In the code from the book on page 288 stands: `

<%=h person.name %></td>

<%= person.name.length %></td>

<%= person.name.chars.length %></td>

<%=h person.name.chars.reverse %></td> `

but this produces just: ` undefined method length' for #<Enumerable::Enumerator:0x7f75ded33fa0> Extracted source (around line #9): <tr> <td><%= h person.name %></td> <td><%= person.name.length %></td> <td><%= person.name.chars.length %></td>

If i switch to mb_chars, like you do in irb-example on starting with 16.9 i got no errors with the following code: ` 7 <td><%= h person.name %></td> 8 <td><%= person.name.length %></td> 9 <td><%= person.name.mb_chars.length %></td> 10 <td><%=h person.name.mb_chars.reverse %></td> `

whats the difference between mb_chars and chars? The funny thing: there is none. But why the hell i got a Enumable as return?

# File activesupport/lib/active_support/core_ext/string/multibyte.rb, line 57 def chars ActiveSupport::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller) mb_chars end

Using the example-setup from the book to confirm the correctness of all examples: Rails 2.2.2 Ruby 1.8 Gems: 1.3.1

on a Ubuntu Linux 8.10 x64

You must be logged in to comment