Changeset 7474
- Timestamp:
- 09/14/07 00:34:43 (1 year ago)
- Files:
-
- trunk/activesupport/lib/active_support/core_ext/array/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/class/removal.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/date_time.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/date/calculations.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/date/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/enumerable.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/exception.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/float/rounding.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/name_error.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/range/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/string.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/symbol.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/time/calculations.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/time/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (4 diffs)
- trunk/activesupport/lib/active_support/deprecation.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/inflector.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/option_merger.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/vendor/builder/xmlbase.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/array_ext_test.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/enumerable_test.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/file_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/array/conversions.rb
r7074 r7474 26 26 join '/' 27 27 end 28 29 def self.included(klass) #:nodoc: 30 klass.send(:alias_method, :to_default_s, :to_s) 31 klass.send(:alias_method, :to_s, :to_formatted_s) 28 29 def self.included(base) #:nodoc: 30 base.class_eval do 31 alias_method :to_default_s, :to_s 32 alias_method :to_s, :to_formatted_s 33 end 32 34 end 33 35 34 36 def to_formatted_s(format = :default) 35 37 case format trunk/activesupport/lib/active_support/core_ext/class/removal.rb
r3668 r7474 18 18 # Skip this class if it does not match the current one bound to this name 19 19 next unless parent.const_defined?(basename) && klass = parent.const_get(basename) 20 21 parent. send :remove_const, basenameunless parent == klass20 21 parent.instance_eval { remove_const basename } unless parent == klass 22 22 end 23 23 end trunk/activesupport/lib/active_support/core_ext/date_time.rb
r6303 r7474 4 4 require "#{File.dirname(__FILE__)}/date_time/conversions" 5 5 6 DateTime.send(:include, ActiveSupport::CoreExtensions::Time::Behavior) 7 DateTime.send(:include, ActiveSupport::CoreExtensions::DateTime::Calculations) 8 DateTime.send(:include, ActiveSupport::CoreExtensions::DateTime::Conversions) 6 class DateTime 7 include ActiveSupport::CoreExtensions::Time::Behavior 8 include ActiveSupport::CoreExtensions::DateTime::Calculations 9 include ActiveSupport::CoreExtensions::DateTime::Conversions 10 end trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb
r6933 r7474 4 4 # Getting datetimes in different convenient string representations and other objects 5 5 module Conversions 6 def self.included(klass) 7 klass.send(:alias_method, :to_datetime_default_s, :to_s) 8 klass.send(:alias_method, :to_s, :to_formatted_s) 9 klass.send(:alias_method, :default_inspect, :inspect) 10 klass.send(:alias_method, :inspect, :readable_inspect) 6 def self.included(base) 7 base.class_eval do 8 alias_method :to_datetime_default_s, :to_s 9 alias_method :to_s, :to_formatted_s 10 alias_method :default_inspect, :inspect 11 alias_method :inspect, :readable_inspect 12 end 11 13 end 12 14 trunk/activesupport/lib/active_support/core_ext/date/calculations.rb
r7262 r7474 5 5 module Calculations 6 6 def self.included(base) #:nodoc: 7 base.send(:extend, ClassMethods) 8 9 base.send(:alias_method, :plus_without_duration, :+) 10 base.send(:alias_method, :+, :plus_with_duration) 11 12 base.send(:alias_method, :minus_without_duration, :-) 13 base.send(:alias_method, :-, :minus_with_duration) 7 base.extend ClassMethods 8 9 base.instance_eval do 10 alias_method :plus_without_duration, :+ 11 alias_method :+, :plus_with_duration 12 13 alias_method :minus_without_duration, :- 14 alias_method :-, :minus_with_duration 15 end 14 16 end 15 17 trunk/activesupport/lib/active_support/core_ext/date/conversions.rb
r6933 r7474 12 12 } 13 13 14 def self.included(klass) #:nodoc: 15 klass.send(:alias_method, :to_default_s, :to_s) 16 klass.send(:alias_method, :to_s, :to_formatted_s) 17 klass.send(:alias_method, :default_inspect, :inspect) 18 klass.send(:alias_method, :inspect, :readable_inspect) 14 def self.included(base) #:nodoc: 15 base.instance_eval do 16 alias_method :to_default_s, :to_s 17 alias_method :to_s, :to_formatted_s 18 alias_method :default_inspect, :inspect 19 alias_method :inspect, :readable_inspect 20 end 19 21 end 20 22 trunk/activesupport/lib/active_support/core_ext/enumerable.rb
r5334 r7474 39 39 def sum(identity = 0, &block) 40 40 return identity unless size > 0 41 41 42 if block_given? 42 43 map(&block).sum trunk/activesupport/lib/active_support/core_ext/exception.rb
r5546 r7474 9 9 def clean_backtrace 10 10 backtrace.collect do |line| 11 Pathname.clean_within(TraceSubstitutions.inject(line) do | line, (regexp, sub)|12 line.gsub regexp, sub11 Pathname.clean_within(TraceSubstitutions.inject(line) do |result, (regexp, sub)| 12 result.gsub regexp, sub 13 13 end) 14 14 end trunk/activesupport/lib/active_support/core_ext/float/rounding.rb
r7401 r7474 4 4 module Rounding 5 5 def self.included(base) #:nodoc: 6 base.send(:alias_method, :round_without_precision, :round) 7 base.send(:alias_method, :round, :round_with_precision) 6 base.class_eval do 7 alias_method :round_without_precision, :round 8 alias_method :round, :round_with_precision 9 end 8 10 end 9 11 trunk/activesupport/lib/active_support/core_ext/name_error.rb
r6044 r7474 1 1 # Add a +missing_name+ method to NameError instances. 2 class NameError < StandardError#:nodoc:2 class NameError #:nodoc: 3 3 # Add a method to obtain the missing name from a NameError. 4 4 def missing_name trunk/activesupport/lib/active_support/core_ext/range/conversions.rb
r2506 r7474 7 7 :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } 8 8 } 9 10 def self.included(klass) #:nodoc: 11 klass.send(:alias_method, :to_default_s, :to_s) 12 klass.send(:alias_method, :to_s, :to_formatted_s) 9 10 def self.included(base) #:nodoc: 11 base.class_eval do 12 alias_method :to_default_s, :to_s 13 alias_method :to_s, :to_formatted_s 14 end 13 15 end 14 16 15 17 def to_formatted_s(format = :default) 16 18 DATE_FORMATS[format] ? DATE_FORMATS[format].call(first, last) : to_default_s trunk/activesupport/lib/active_support/core_ext/string.rb
r5223 r7474 3 3 require File.dirname(__FILE__) + '/string/access' 4 4 require File.dirname(__FILE__) + '/string/starts_ends_with' 5 require File.dirname(__FILE__) + '/string/iterators' 5 require File.dirname(__FILE__) + '/string/iterators' unless 'test'.respond_to?(:each_char) 6 6 require File.dirname(__FILE__) + '/string/unicode' 7 7 … … 11 11 include ActiveSupport::CoreExtensions::String::Inflections 12 12 include ActiveSupport::CoreExtensions::String::StartsEndsWith 13 include ActiveSupport::CoreExtensions::String::Iterators 13 if defined? ActiveSupport::CoreExtensions::String::Iterators 14 include ActiveSupport::CoreExtensions::String::Iterators 15 end 14 16 include ActiveSupport::CoreExtensions::String::Unicode 15 17 end trunk/activesupport/lib/active_support/core_ext/symbol.rb
r4455 r7474 1 class Symbol 2 # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: 3 # 4 # # The same as people.collect { |p| p.name } 5 # people.collect(&:name) 6 # 7 # # The same as people.select { |p| p.manager? }.collect { |p| p.salary } 8 # people.select(&:manager?).collect(&:salary) 9 def to_proc 10 Proc.new { |*args| args.shift.__send__(self, *args) } 1 unless :test.respond_to?(:to_proc) 2 class Symbol 3 # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: 4 # 5 # # The same as people.collect { |p| p.name } 6 # people.collect(&:name) 7 # 8 # # The same as people.select { |p| p.manager? }.collect { |p| p.salary } 9 # people.select(&:manager?).collect(&:salary) 10 def to_proc 11 Proc.new { |*args| args.shift.__send__(self, *args) } 12 end 11 13 end 12 14 end trunk/activesupport/lib/active_support/core_ext/time/calculations.rb
r7262 r7474 5 5 module Calculations 6 6 def self.included(base) #:nodoc: 7 base.extend(ClassMethods) 8 9 base.send(:alias_method, :plus_without_duration, :+) 10 base.send(:alias_method, :+, :plus_with_duration) 11 base.send(:alias_method, :minus_without_duration, :-) 12 base.send(:alias_method, :-, :minus_with_duration) 7 base.extend ClassMethods 8 9 base.class_eval do 10 alias_method :plus_without_duration, :+ 11 alias_method :+, :plus_with_duration 12 alias_method :minus_without_duration, :- 13 alias_method :-, :minus_with_duration 14 end 13 15 end 14 16 trunk/activesupport/lib/active_support/core_ext/time/conversions.rb
r6902 r7474 13 13 } 14 14 15 def self.included(klass) 16 klass.send(:alias_method, :to_default_s, :to_s) 17 klass.send(:alias_method, :to_s, :to_formatted_s) 15 def self.included(base) 16 base.class_eval do 17 alias_method :to_default_s, :to_s 18 alias_method :to_s, :to_formatted_s 19 end 18 20 end 19 21 trunk/activesupport/lib/active_support/dependencies.rb
r6443 r7474 115 115 /^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ path 116 116 117 names = path. split('::')117 names = path.to_s.split('::') 118 118 names.shift if names.first.empty? 119 119 … … 412 412 413 413 const = $1 if /\A::(.*)\Z/ =~ const.to_s 414 names = const. split('::')414 names = const.to_s.split('::') 415 415 if names.size == 1 # It's under Object 416 416 parent = Object … … 420 420 421 421 log "removing constant #{const}" 422 parent. send :remove_const, names.last422 parent.instance_eval { remove_const names.last } 423 423 return true 424 424 end … … 439 439 end 440 440 441 Object.send(:define_method, :require_or_load) { |file_name| Dependencies.require_or_load(file_name) } unless Object.respond_to?(:require_or_load) 442 Object.send(:define_method, :require_dependency) { |file_name| Dependencies.depend_on(file_name) } unless Object.respond_to?(:require_dependency) 443 Object.send(:define_method, :require_association) { |file_name| Dependencies.associate_with(file_name) } unless Object.respond_to?(:require_association) 441 Object.instance_eval do 442 define_method(:require_or_load) { |file_name| Dependencies.require_or_load(file_name) } unless Object.respond_to?(:require_or_load) 443 define_method(:require_dependency) { |file_name| Dependencies.depend_on(file_name) } unless Object.respond_to?(:require_dependency) 444 define_method(:require_association) { |file_name| Dependencies.associate_with(file_name) } unless Object.respond_to?(:require_association) 445 end 444 446 445 447 class Module #:nodoc: trunk/activesupport/lib/active_support/deprecation.rb
r7220 r7474 148 148 # warnings on any method call (except #inspect). 149 149 class DeprecatedInstanceVariableProxy #:nodoc: 150 instance_methods.each { |m| undef_method m unless m =~ /^__/ } 150 silence_warnings do 151 instance_methods.each { |m| undef_method m unless m =~ /^__/ } 152 end 151 153 152 154 def initialize(instance, method, var = "@#{method}") trunk/activesupport/lib/active_support/inflector.rb
r7092 r7474 271 271 else 272 272 case number.to_i % 10 273 when 1 :"#{number}st"274 when 2 :"#{number}nd"275 when 3 :"#{number}rd"273 when 1; "#{number}st" 274 when 2; "#{number}nd" 275 when 3; "#{number}rd" 276 276 else "#{number}th" 277 277 end trunk/activesupport/lib/active_support/option_merger.rb
r5197 r7474 2 2 class OptionMerger #:nodoc: 3 3 instance_methods.each do |method| 4 undef_method(method) if method !~ /^(__|instance_eval|class )/4 undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/ 5 5 end 6 6 trunk/activesupport/lib/active_support/vendor/builder/xmlbase.rb
r4839 r7474 123 123 124 124 def _capture_outer_self(block) 125 @self = eval( "self", block)125 @self = eval('self', block.instance_eval { binding }) 126 126 end 127 127 128 128 def _newline 129 129 return if @indent == 0 130 130 text! "\n" 131 131 end 132 132 133 133 def _indent 134 134 return if @indent == 0 || @level == 0 135 135 text!(" " * (@level * @indent)) 136 136 end 137 137 138 138 def _nested_structures(block) 139 139 @level += 1 trunk/activesupport/test/core_ext/array_ext_test.rb
r7217 r7474 180 180 assert_equal 0, xml.rindex(/<\?xml /) 181 181 end 182 182 183 183 def test_to_xml_with_block 184 184 xml = [ 185 185 { :name => "David", :age => 26, :age_in_millis => 820497600000 }, 186 186 { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') } 187 ].to_xml(:skip_instruct => true, :indent => 0) do | xml|188 xml.count 2189 end 190 187 ].to_xml(:skip_instruct => true, :indent => 0) do |builder| 188 builder.count 2 189 end 190 191 191 assert xml.include?(%(<count>2</count>)), xml 192 192 end trunk/activesupport/test/core_ext/enumerable_test.rb
r4599 r7474 9 9 def test_group_by 10 10 names = %w(marcel sam david jeremy) 11 klass = Class.new 12 klass.send(:attr_accessor, :name) 11 klass = Struct.new(:name) 13 12 objects = (1..50).inject([]) do |people,| 14 13 p = klass.new … … 39 38 40 39 def test_nil_sums 41 assert_raise(TypeError) { [5, 15, nil].sum } 40 expected_raise = RUBY_VERSION < '1.9.0' ? TypeError : NoMethodError 41 42 assert_raise(expected_raise) { [5, 15, nil].sum } 42 43 43 44 payments = [ Payment.new(5), Payment.new(15), Payment.new(10), Payment.new(nil) ] 44 assert_raise(TypeError) { payments.sum(&:price) } 45 assert_raise(expected_raise) { payments.sum(&:price) } 46 45 47 assert_equal 60, payments.sum { |p| p.price.to_i * 2 } 46 48 end trunk/activesupport/test/core_ext/file_test.rb
r7412 r7474 7 7 File.atomic_write(file_name, Dir.pwd) do |file| 8 8 file.write(contents) 9 assert !File.exist s?(file_name)9 assert !File.exist?(file_name) 10 10 end 11 assert File.exist s?(file_name)11 assert File.exist?(file_name) 12 12 assert_equal contents, File.read(file_name) 13 13 ensure … … 21 21 end 22 22 rescue 23 assert !File.exist s?(file_name)23 assert !File.exist?(file_name) 24 24 end 25 25