Skip to content

Commit

Permalink
add metaclass to Object
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Nov 14, 2009
1 parent 82b970e commit cd1acea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
5 changes: 5 additions & 0 deletions lib/i18n/core_ext/object/meta_class.rb
@@ -0,0 +1,5 @@
Object.class_eval do
def meta_class
class << self; self; end
end
end unless Object.method_defined?(:meta_class)
8 changes: 4 additions & 4 deletions test/backend/fallbacks/fallbacks_test.rb
Expand Up @@ -13,17 +13,17 @@ def setup
define_method "test: fallbacks for :de are [:de, :en]" do
assert_equal [:de, :en], I18n.fallbacks[:de]
end

define_method "test: still returns the English translation as usual" do
assert_equal 'Foo', I18n.t(:foo, :locale => :en)
end

define_method "test: returns the English translation for a missing German translation" do
assert_equal 'Foo', I18n.t(:foo, :locale => :de)
end

define_method "test: raises I18n::MissingTranslationData exception when no translation was found" do
assert_raises(I18n::MissingTranslationData) { I18n.t(:bar, :locale => :en, :raise => true) }
assert_raises(I18n::MissingTranslationData) { I18n.t(:bar, :locale => :de, :raise => true) }
end
end
end
9 changes: 2 additions & 7 deletions test/test_helper.rb
Expand Up @@ -6,6 +6,7 @@
require 'test/unit'
require 'mocha'
require 'i18n'
require 'i18n/core_ext/object/meta_class'
require 'time'
require 'yaml'

Expand All @@ -27,7 +28,7 @@ def self.test(name, &block)
def euc_jp(string)
string.encode!(Encoding::EUC_JP)
end

def locales_dir
File.dirname(__FILE__) + '/fixtures/locales'
end
Expand Down Expand Up @@ -63,10 +64,4 @@ def evening_time
end
end

class Object
def meta_class
class << self; self; end
end
end


0 comments on commit cd1acea

Please sign in to comment.