Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8759: array_extract_options.2.patch

File array_extract_options.2.patch, 1.7 kB (added by norbert, 1 year ago)

No more self!?

  • activesupport/test/core_ext/array_ext_test.rb

    old new  
    191191    assert xml.include?(%(<count>2</count>)), xml 
    192192  end 
    193193end 
     194 
     195class ArrayTests < Test::Unit::TestCase 
     196  def test_extract_options 
     197    assert_equal({}, [].extract_options!) 
     198    assert_equal({}, [1].extract_options!) 
     199    assert_equal({:a=>:b}, [1, {:a=>:b}].extract_options!) 
     200  end 
     201end 
  • activesupport/lib/active_support/core_ext/array.rb

    old new  
    11require File.dirname(__FILE__) + '/array/conversions' 
    22require File.dirname(__FILE__) + '/array/grouping' 
     3require File.dirname(__FILE__) + '/array/misc' 
    34 
    45class Array #:nodoc: 
    56  include ActiveSupport::CoreExtensions::Array::Conversions 
  • activesupport/lib/active_support/core_ext/array/misc.rb

    old new  
     1class Array 
     2  # Extract options from a set of arguments. Removes and returns the last element in the array if it's a hash, otherwise returns a blank hash. 
     3  # 
     4  #   def options(*args) 
     5  #     args.extract_options! 
     6  #   end 
     7  # 
     8  #   options(1, 2)           # => {} 
     9  #   options(1, 2, :a => :b) # => {:a=>:b} 
     10  def extract_options! 
     11    last.is_a?(Hash) ? pop : {} 
     12  end 
     13end