Skip to content

Instantly share code, notes, and snippets.

View norman's full-sized avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
$ irb
ruby-1.9.1-p378 > string = "Jürgen Müller"
=> "Jürgen Müller"
ruby-1.9.1-p378 > string.force_encoding("BINARY").encode("UTF-8", :invalid => :replace, :replace => "")
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
from (irb):2:in `encode'
from (irb):2
from /Users/norman/.rvm/rubies/ruby-1.9.1-p378/bin/irb:17:in `<main>'
ruby-1.9.1-p378 >
module MyApp
module Friendly
def self.included(base)
base.has_friendly_id :custom_slug, :use_slug => true, :approximate_ascii => true
end
def custom_slug
if @custom_slug.present?
From a62b79e86cb2ad973578be43d93f79890ed0ab4d Mon Sep 17 00:00:00 2001
From: Norman Clarke <norman@njclarke.com>
Date: Wed, 7 Apr 2010 16:21:41 -0300
Subject: [PATCH] Make tidy_bytes work on 1.9 and improve its performance. [#4350 state:resolved]
---
.../lib/active_support/multibyte/chars.rb | 85 +++++++++++++++----
activesupport/test/multibyte_chars_test.rb | 73 +++++++++++------
2 files changed, 114 insertions(+), 44 deletions(-)
From 059e245874dd38843986a8c0226c4dfad835bfff Mon Sep 17 00:00:00 2001
From: Norman Clarke <norman@njclarke.com>
Date: Mon, 12 Apr 2010 12:44:25 -0300
Subject: [PATCH] Improve reliability of Inflector.transliterate. [#4374 state:resolved]
---
.../lib/active_support/inflector/transliterate.rb | 61 ++++++++++++--------
activesupport/test/inflector_test_cases.rb | 5 +-
activesupport/test/transliterate_test.rb | 50 ++++++++++++++++
3 files changed, 91 insertions(+), 25 deletions(-)
# Ruby surprisingly clears the value of the $1 variable after a return
def test_gsub
result = "a".gsub(/(a)/, "b")
p $1
result
end
test_gsub
p $1
I18n.backend.store_translations(:foo, :test => {:a => "b"})
I18n.backend.store_translations(:foo2, :test => lambda {|*args| args.join(", ")})
p I18n.t 'test', :locale => :foo # {:a=>"b"}
p I18n.t 'test', :locale => :foo2 # "test, "
class Author < ActiveRecord::Base
has_many :books
end
class Book < ActiveRecord::Base
belongs_to :author
end
@author = Author.find(params[:id], :include => :books)
class Sound < Test::Unit::TestCase
include Spanish::Phonology
test "should get sound from symbol" do
sound = Sound.new("b")
assert_equal "b", sound.symbol
assert sound.labial?
assert sound.stop?
assert sound.consonantal?
# ruby-1.9.1-p243
"é".center(5, 'a') # => "aaéaa"
"é".center(5, "á") # => "ááéáá"
# ruby-1.9.1-p378
"é".center(5, 'a') # => "aaéaa"
"é".center(5, 'á') # => "áéá"