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

Changeset 2422

Show
Ignore:
Timestamp:
09/30/05 07:14:37 (3 years ago)
Author:
david
Message:

Added method access to OrdredOptions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/ordered_options.rb

    r2419 r2422  
    1616  end 
    1717 
     18  def method_missing(name, *args) 
     19    if name.to_s =~ /(.*)=$/ 
     20      self[$1.to_sym] = args.first 
     21    else 
     22      self[name] 
     23    end 
     24  end 
     25 
    1826  private 
    1927    def find_pair(key) 
  • trunk/activesupport/test/ordered_options_test.rb

    r2420 r2422  
    3535    end 
    3636  end 
     37   
     38  def test_method_access 
     39    a = OrderedOptions.new 
     40 
     41    assert_nil a.not_set 
     42 
     43    a.allow_concurreny = true     
     44    assert_equal 1, a.size 
     45    assert a.allow_concurreny 
     46 
     47    a.allow_concurreny = false 
     48    assert_equal 1, a.size 
     49    assert !a.allow_concurreny 
     50 
     51    a.else_where = 56 
     52    assert_equal 2, a.size 
     53    assert_equal 56, a.else_where 
     54  end 
    3755end