Skip to content

Commit

Permalink
don't use a class variable to store the connector instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Dec 24, 2010
1 parent 1d45b59 commit 79c03af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 6 additions & 7 deletions lib/to_lang.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
require File.expand_path("../to_lang/connector", __FILE__)

module ToLang
def self.start(key)
@@connector = ToLang::Connector.new(key)
class << self
attr_reader :connector

String.send(:include, InstanceMethods)
end

def self.connector
@@connector
def start(key)
@connector = ToLang::Connector.new(key)
String.send(:include, InstanceMethods)
end
end

module InstanceMethods
Expand Down
7 changes: 3 additions & 4 deletions test/to_lang_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
require 'to_lang'

class ToLang::ToLangTest < Test::Unit::TestCase
def test_connector_should_not_exist_by_default
assert_raise NameError do
ToLang.connector
end
def test_connector_should_not_exist_before_calling_start
assert_nil ToLang.connector
end

def test_start_should_initialize_connector
Expand All @@ -17,6 +15,7 @@ def test_start_should_initialize_connector

def test_start_should_include_instance_methods_in_string
ToLang.start('abcdefg')
assert String.include? ::ToLang::InstanceMethods
assert_respond_to 'test string', :translate
end
end

0 comments on commit 79c03af

Please sign in to comment.