From a599a26f1abfc06bc03608c6c210e73509757c8a Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Thu, 31 Oct 2013 15:33:56 -0400 Subject: [PATCH] Remove some legacy Ruby 1.8 compatibility code --- History.md | 1 + lib/liquid/drop.rb | 9 ++++----- lib/liquid/standardfilters.rb | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/History.md b/History.md index 35fde61..2d940ba 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,7 @@ ## 3.0.0 / not yet released / branch "master" * ... +* Remove some legacy Ruby 1.8 compatibility code, see #276 [Florian Weingarten, fw42] * Add default filter to standard filters, see #267 [Derrick Reimer, djreimer] * Add optional strict parsing and warn parsing, see #235 [Tristan Hume, trishume] * Add I18n syntax error translation, see #241 [Simon Hørup Eskildsen, Sirupsen] diff --git a/lib/liquid/drop.rb b/lib/liquid/drop.rb index f1bf48a..d4e5941 100644 --- a/lib/liquid/drop.rb +++ b/lib/liquid/drop.rb @@ -59,13 +59,12 @@ module Liquid # Check for method existence without invoking respond_to?, which creates symbols def self.invokable?(method_name) unless @invokable_methods - # Ruby 1.8 compatibility: call to_s on method names (which are strings in 1.8, but already symbols in 1.9) - blacklist = (Liquid::Drop.public_instance_methods + [:each]).map(&:to_s) + blacklist = Liquid::Drop.public_instance_methods + [:each] if include?(Enumerable) - blacklist += Enumerable.public_instance_methods.map(&:to_s) - blacklist -= [:sort, :count, :first, :min, :max, :include?].map(&:to_s) + blacklist += Enumerable.public_instance_methods + blacklist -= [:sort, :count, :first, :min, :max, :include?] end - whitelist = [:to_liquid] + (public_instance_methods.map(&:to_s) - blacklist.map(&:to_s)) + whitelist = [:to_liquid] + (public_instance_methods - blacklist) @invokable_methods = Set.new(whitelist.map(&:to_s)) end @invokable_methods.include?(method_name.to_s) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index c938f3a..54ab799 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -43,8 +43,7 @@ module Liquid if input.nil? then return end l = length.to_i - truncate_string.length l = 0 if l < 0 - truncated = RUBY_VERSION[0,3] == "1.8" ? input.scan(/./mu)[0...l].to_s : input[0...l] - input.length > length.to_i ? truncated + truncate_string : input + input.length > length.to_i ? input[0...l] + truncate_string : input end def truncatewords(input, words = 15, truncate_string = "...")