Changeset 9156
- Timestamp:
- 03/31/08 01:09:39 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
r8056 r9156 20 20 self.class.#{name} 21 21 end 22 def self.#{name}? 23 !!#{name} 24 end 25 def #{name}? 26 !!#{name} 27 end 22 28 EOS 23 29 end trunk/activesupport/test/core_ext/class/delegating_attributes_test.rb
r8563 r9156 26 26 # should be no mutator 27 27 assert single_class.respond_to?(:only_reader) 28 assert single_class.respond_to?(:only_reader?) 28 29 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?") 29 31 assert !single_class.respond_to?(:only_reader=) 30 32 end … … 52 54 def test_working_with_simple_attributes 53 55 single_class.superclass_delegating_accessor :both 54 single_class.both= "HMMM" 56 57 single_class.both = "HMMM" 58 55 59 assert_equal "HMMM", single_class.both 60 assert_equal true, single_class.both? 61 56 62 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? 57 67 end 58 68 … … 74 84 parent.superclass_delegating_accessor :both 75 85 child = Class.new(parent) 76 parent.both = "1"86 parent.both = "1" 77 87 assert_equal "1", child.both 78 88 79 child.both ="2"89 child.both = "2" 80 90 assert_equal "1", parent.both 81 91 assert_equal "2", child.both 82 92 83 parent.both ="3"93 parent.both = "3" 84 94 assert_equal "3", parent.both 85 95 assert_equal "2", child.both