From 97782e659632e43b1329a1a8f2e7018a47ae4d3d Mon Sep 17 00:00:00 2001 From: elliottcable Date: Thu, 11 Jun 2009 13:00:43 -0800 Subject: [PATCH] Pushing a Ruby warning when overriding String#each, but only worrying about it pre-1.9 --- .manifest | 8 +++++--- lib/stringray.rb | 7 ++++++- lib/stringray/core_ext.rb | 1 + lib/stringray/core_ext/kernel.rb | 6 ++++++ stringray.gemspec | 4 ++-- 5 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 lib/stringray/core_ext.rb create mode 100644 lib/stringray/core_ext/kernel.rb diff --git a/.manifest b/.manifest index 4a3b5b3..eb91dba 100644 --- a/.manifest +++ b/.manifest @@ -1,6 +1,8 @@ -lib/stringray/core_ext/spec/rake/verify_rcov.rb lib/stringray.rb -Rakefile.rb -README.markdown +lib/stringray/core_ext.rb +lib/stringray/core_ext/kernel.rb +lib/stringray/core_ext/spec/rake/verify_rcov.rb spec/stringray_spec.rb +README.markdown +Rakefile.rb .manifest diff --git a/lib/stringray.rb b/lib/stringray.rb index 9c2c9ed..f599a8f 100644 --- a/lib/stringray.rb +++ b/lib/stringray.rb @@ -1,3 +1,5 @@ +require 'stringray/core_ext' + module StringRay VERSION = 2 @@ -212,7 +214,10 @@ module StringRay # +String#each_at+. def make_enumerable! self.class_eval do - alias_method :each_at, :each if RUBY_VERSION <= "1.9" + if RUBY_VERSION <= "1.9" + Kernel::warn "overriding String#each with StringRay#enumerate; this may break old libaries!" + alias_method :each_at, :each + end alias_method :each, :enumerate include Enumerable diff --git a/lib/stringray/core_ext.rb b/lib/stringray/core_ext.rb new file mode 100644 index 0000000..79105e4 --- /dev/null +++ b/lib/stringray/core_ext.rb @@ -0,0 +1 @@ +require 'stringray/core_ext/kernel' diff --git a/lib/stringray/core_ext/kernel.rb b/lib/stringray/core_ext/kernel.rb new file mode 100644 index 0000000..321a8a8 --- /dev/null +++ b/lib/stringray/core_ext/kernel.rb @@ -0,0 +1,6 @@ +module Kernel + def self.warn message + super "#{caller[-1]}: warning: #{message}" + end +end + diff --git a/stringray.gemspec b/stringray.gemspec index 014268e..9e4f7aa 100644 --- a/stringray.gemspec +++ b/stringray.gemspec @@ -9,8 +9,8 @@ Gem::Specification.new do |s| s.date = %q{2009-06-11} s.description = %q{Combining many of the benefits of Arrays and Strings, StringRay allows you to treat a String as an Array of words in many cases.} s.email = ["StringRay@elliottcable.com"] - s.extra_rdoc_files = ["lib/stringray/core_ext/spec/rake/verify_rcov.rb", "lib/stringray.rb", "README.markdown"] - s.files = ["lib/stringray/core_ext/spec/rake/verify_rcov.rb", "lib/stringray.rb", "Rakefile.rb", "README.markdown", "spec/stringray_spec.rb", ".manifest", "stringray.gemspec"] + s.extra_rdoc_files = ["lib/stringray.rb", "lib/stringray/core_ext.rb", "lib/stringray/core_ext/kernel.rb", "lib/stringray/core_ext/spec/rake/verify_rcov.rb", "README.markdown"] + s.files = ["lib/stringray.rb", "lib/stringray/core_ext.rb", "lib/stringray/core_ext/kernel.rb", "lib/stringray/core_ext/spec/rake/verify_rcov.rb", "spec/stringray_spec.rb", "README.markdown", "Rakefile.rb", ".manifest", "stringray.gemspec"] s.has_rdoc = true s.homepage = %q{http://github.com/elliottcable/stringray} s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Stringray", "--main", "README.markdown"] -- 2.11.4.GIT