Last active
August 29, 2015 14:21
-
-
Save sshao/8d26bd8c9a50e5b4b2fb to your computer and use it in GitHub Desktop.
This file contains 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 characters
$ ruby -v test.rb | |
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14] | |
t.value: accessor-set value. didn't go through the defined method! |
This file contains 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 characters
module TestModule | |
define_method "value=".to_sym do |v| | |
instance_variable_set("@value".to_sym, "defined method set this value") | |
end | |
end | |
class Test | |
include TestModule | |
attr_accessor :value | |
end | |
t = Test.new | |
t.value = "accessor-set value. didn't go through the defined method!" | |
puts "t.value: #{t.value}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment