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

Changeset 9156

Show
Ignore:
Timestamp:
03/31/08 01:09:39 (5 months ago)
Author:
bitsweat
Message:

Add query methods for superclass_delegating_reader

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb

    r8056 r9156  
    2020        self.class.#{name} 
    2121      end 
     22      def self.#{name}? 
     23        !!#{name} 
     24      end 
     25      def #{name}? 
     26        !!#{name} 
     27      end 
    2228      EOS 
    2329    end 
  • trunk/activesupport/test/core_ext/class/delegating_attributes_test.rb

    r8563 r9156  
    2626    # should be no mutator 
    2727    assert single_class.respond_to?(:only_reader) 
     28    assert single_class.respond_to?(:only_reader?) 
    2829    assert single_class.public_instance_methods.map(&:to_s).include?("only_reader") 
     30    assert single_class.public_instance_methods.map(&:to_s).include?("only_reader?") 
    2931    assert !single_class.respond_to?(:only_reader=) 
    3032  end 
     
    5254  def test_working_with_simple_attributes 
    5355    single_class.superclass_delegating_accessor :both 
    54     single_class.both= "HMMM" 
     56 
     57    single_class.both = "HMMM" 
     58 
    5559    assert_equal "HMMM", single_class.both 
     60    assert_equal true, single_class.both? 
     61 
    5662    assert_equal "HMMM", single_class.new.both 
     63    assert_equal true, single_class.new.both? 
     64 
     65    single_class.both = false 
     66    assert_equal false, single_class.both? 
    5767  end 
    5868 
     
    7484    parent.superclass_delegating_accessor :both 
    7585    child = Class.new(parent) 
    76     parent.both= "1" 
     86    parent.both = "1" 
    7787    assert_equal "1", child.both 
    7888 
    79     child.both="2" 
     89    child.both = "2" 
    8090    assert_equal "1", parent.both 
    8191    assert_equal "2", child.both 
    8292 
    83     parent.both="3" 
     93    parent.both = "3" 
    8494    assert_equal "3", parent.both 
    8595    assert_equal "2", child.both