-
-
Save jm/445160 to your computer and use it in GitHub Desktop.
Revisions
-
jm revised this gist
Jun 19, 2010 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ class ClassWithAttr def self.my_attr_accessor(attr_name) define_method("#{attr_name}=") do |arg| instance_variable_set("@#{attr_name}", arg) end define_method(attr_name) do -
jm revised this gist
Jun 19, 2010 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ def self.my_attr_accessor(attr_name) define_method("#{attr_name.to_s}=") do |arg| instance_variable_set("@#{attr_name}", arg) end define_method(attr_name) do instance_variable_get("@#{attr_name}") end end -
danielwellman created this gist
Jun 19, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ class ClassWithAttr def self.my_attr_accessor(attr_name) define_method("#{attr_name.to_s}=") do |arg| instance_variable_set("@#{attr_name}", arg) end define_method("#{attr_name.to_s}") do instance_variable_get("@#{attr_name}") end end my_attr_accessor :name end if __FILE__ == $PROGRAM_NAME require "test/unit" require 'rubygems' require 'mocha' class AttrTest < Test::Unit::TestCase def test_my_attr_accessor person = ClassWithAttr.new person.name = "Dan" assert_equal "Dan", person.name end end end