Skip to content

Instantly share code, notes, and snippets.

@cscotta
Created July 14, 2009 05:01
Show Gist options
  • Save cscotta/146722 to your computer and use it in GitHub Desktop.
Save cscotta/146722 to your computer and use it in GitHub Desktop.
=== Simplest Form
insight:~ cscotta$ irb
irb(main):001:0> require 'activesupport'
=> true
irb(main):002:0> RUBY_VERSION
=> "1.9.1"
irb(main):003:0> "3437 Coeur D\xD5Alene".encoding
=> #<Encoding:UTF-8>
irb(main):004:0> "3437 Coeur D\xD5Alene".valid_encoding?
=> false
irb(main):005:0> "3437 Coeur D\xD5Alene".blank?
ArgumentError: invalid byte sequence in UTF-8
from /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/core_ext/blank.rb:50:in `=~'
from /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/core_ext/blank.rb:50:in `!~'
from /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/core_ext/blank.rb:50:in `blank?'
from (irb):5
from /usr/bin/irb:13:in `<main>'
irb(main):006:0>
=== Initial Reduction from Application
insight:sunago cscotta$ script/console
Loading development environment (Rails 2.3.2)
>> RUBY_VERSION
=> "1.9.1"
>> a = Individual.find(xxx)
=> #<Individual id: xxx ... address1: "3437 Coeur D\xD5Alene">
>> a.address1
=> "3437 Coeur D\xD5Alene"
>> a.address1.encoding
=> #<Encoding:ASCII-8BIT>
>> a.address1.valid_encoding?
=> true
>> a.address1.force_encoding(Encoding::UTF_8)
=> "3437 Coeur D\xD5Alene"
>> a.address1.valid_encoding?
=> false
>> a.address1
=> "3437 Coeur D\xD5Alene"
>> a.address1.blank?
ArgumentError: invalid byte sequence in UTF-8
from /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/core_ext/blank.rb:50:in `=~'
from /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/core_ext/blank.rb:50:in `!~'
from /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/core_ext/blank.rb:50:in `blank?'
from (irb):29
from /usr/bin/irb:13:in `<main>'
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment