From 334ca54a53a0b5776d1279168782c238aa79b5f6 Mon Sep 17 00:00:00 2001 From: Semyon Pupkov Date: Mon, 3 Apr 2017 18:18:01 +0500 Subject: [PATCH] fix: allow to use ActiveSupport::Multibyte::Chars in to_b --- lib/string_tools/string.rb | 2 +- spec/string_tools/string_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/string_tools/string.rb b/lib/string_tools/string.rb index 25a8c4c..9b6fb29 100644 --- a/lib/string_tools/string.rb +++ b/lib/string_tools/string.rb @@ -3,7 +3,7 @@ class String TRUE_VALUES = %w(1 t T true TRUE on ON).to_set def initialize(string) - @string = string + @string = string.to_s end # Public: cast string value to boolean diff --git a/spec/string_tools/string_spec.rb b/spec/string_tools/string_spec.rb index 766be8b..3e108f2 100644 --- a/spec/string_tools/string_spec.rb +++ b/spec/string_tools/string_spec.rb @@ -12,4 +12,9 @@ expect(described_class.new(val).to_b).to be true end end + + it 'allows to pass object responded to_s' do + expect(described_class.new(ActiveSupport::Multibyte::Chars.new('t')).to_b).to be true + expect(described_class.new(ActiveSupport::Multibyte::Chars.new('f')).to_b).to be false + end end